Changeset 72 for trunk/src/main/java/omq/common/util/Serializers
- Timestamp:
- 06/29/13 20:44:27 (11 years ago)
- Location:
- trunk/src/main/java/omq/common/util/Serializers
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/main/java/omq/common/util/Serializers/GsonImp.java
r50 r72 3 3 import java.util.List; 4 4 5 import omq.common.event.Event;6 5 import omq.common.message.Request; 7 6 import omq.common.message.Response; … … 75 74 } 76 75 77 @Override78 public Event deserializeEvent(byte[] bytes) throws SerializerException {79 try {80 String json = new String(bytes);81 82 JsonParser parser = new JsonParser();83 JsonObject jsonObj = parser.parse(json).getAsJsonObject();84 85 String type = jsonObj.get("type").getAsString();86 87 JsonElement jsonElement = jsonObj.get("event");88 Event event;89 90 event = (Event) gson.fromJson(jsonElement, Class.forName(type));91 92 return event;93 } catch (Exception e) {94 throw new SerializerException("Deserialize event", e.getCause());95 }96 }97 98 76 } -
trunk/src/main/java/omq/common/util/Serializers/ISerializer.java
r44 r72 1 1 package omq.common.util.Serializers; 2 2 3 import omq.common.event.Event;4 3 import omq.common.message.Request; 5 4 import omq.common.message.Response; … … 18 17 19 18 public Response deserializeResponse(byte[] bytes, Class<?> type) throws SerializerException; 20 21 public Event deserializeEvent(byte[] bytes) throws SerializerException;22 19 } -
trunk/src/main/java/omq/common/util/Serializers/JavaImp.java
r44 r72 6 6 import java.io.ObjectOutputStream; 7 7 8 import omq.common.event.Event;9 import omq.common.event.EventWrapper;10 8 import omq.common.message.Request; 11 9 import omq.common.message.Response; … … 51 49 } 52 50 53 @Override54 public Event deserializeEvent(byte[] bytes) throws SerializerException {55 EventWrapper wrapper = (EventWrapper) deserializeObject(bytes);56 return wrapper.getEvent();57 }58 59 51 public Object deserializeObject(byte[] bytes) throws SerializerException { 60 52 try { -
trunk/src/main/java/omq/common/util/Serializers/KryoImp.java
r44 r72 3 3 import java.io.ByteArrayOutputStream; 4 4 5 import com.esotericsoftware.kryo.Kryo;6 import com.esotericsoftware.kryo.io.Input;7 import com.esotericsoftware.kryo.io.Output;8 9 import omq.common.event.Event;10 import omq.common.event.EventWrapper;11 5 import omq.common.message.Request; 12 6 import omq.common.message.Response; 13 7 import omq.exception.SerializerException; 14 8 import omq.server.RemoteObject; 9 10 import com.esotericsoftware.kryo.Kryo; 11 import com.esotericsoftware.kryo.io.Input; 12 import com.esotericsoftware.kryo.io.Output; 15 13 16 14 /** … … 53 51 } 54 52 55 @Override56 public Event deserializeEvent(byte[] bytes) throws SerializerException {57 EventWrapper wrapper = (EventWrapper) deserializeObject(bytes, EventWrapper.class);58 return wrapper.getEvent();59 }60 61 53 public Object deserializeObject(byte[] bytes, Class<?> type) throws SerializerException { 62 54 try {
Note: See TracChangeset
for help on using the changeset viewer.