Changeset 6 for objectmq/src/omq/common/util/Serializers/JsonImp.java
- Timestamp:
- 05/09/13 17:34:07 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
objectmq/src/omq/common/util/Serializers/JsonImp.java
r3 r6 1 1 package omq.common.util.Serializers; 2 2 3 import omq.common.message.request.AsyncRequest;4 import omq.common.message.request.SyncRequest;5 import omq.common.message.response.CollectionResponse;6 import omq.common.message.response.DefaultResponse;7 import omq.common.message.response.ExceptionResponse;8 import omq.common.message.response.ProxyResponse;9 import omq.common.message.response.Response;10 3 import omq.exception.SerializerException; 11 4 … … 20 13 public class JsonImp implements ISerializer { 21 14 private final ObjectMapper mapper = new ObjectMapper(); 22 15 23 16 @Override 24 17 public byte[] serialize(Object obj) throws SerializerException { … … 30 23 } 31 24 } 32 25 33 26 @Override 34 27 public byte[] serialize(Object obj, Class<?> clazz) throws SerializerException { 35 28 return serialize(obj); 36 } 37 38 39 private Object tryDeserialize(byte[] bytes, Class<?> clazz) throws Exception{ 29 } 30 31 private Object tryDeserialize(byte[] bytes, Class<?> clazz) throws Exception { 40 32 Object object = mapper.readValue(bytes, clazz); 41 33 return object; 42 34 } 43 44 35 45 36 @Override 46 37 public Object deserialize(byte[] bytes) throws SerializerException { 47 try { 48 return tryDeserialize(bytes, SyncRequest.class); 49 } catch (Exception e) { 50 try { 51 return tryDeserialize(bytes, AsyncRequest.class); 52 } catch (Exception e1) { 53 try { 54 return tryDeserialize(bytes, CollectionResponse.class); 55 } catch (Exception e2) { 56 try { 57 return tryDeserialize(bytes, DefaultResponse.class); 58 } catch (Exception e3) { 59 try { 60 return tryDeserialize(bytes, ExceptionResponse.class); 61 } catch (Exception e4) { 62 try { 63 return tryDeserialize(bytes, ProxyResponse.class); 64 } catch (Exception e5) { 65 try { 66 return tryDeserialize(bytes, Response.class); 67 } catch (Exception e6) { 68 throw new SerializerException("Deserialize -> " + e6.getMessage(), e6); 69 } 70 } 71 } 72 } 73 } 74 } 75 } 38 // try { 39 // return tryDeserialize(bytes, SyncRequest.class); 40 // } catch (Exception e) { 41 // try { 42 // return tryDeserialize(bytes, AsyncRequest.class); 43 // } catch (Exception e1) { 44 // try { 45 // return tryDeserialize(bytes, CollectionResponse.class); 46 // } catch (Exception e2) { 47 // try { 48 // return tryDeserialize(bytes, DefaultResponse.class); 49 // } catch (Exception e3) { 50 // try { 51 // return tryDeserialize(bytes, ExceptionResponse.class); 52 // } catch (Exception e4) { 53 // try { 54 // return tryDeserialize(bytes, ProxyResponse.class); 55 // } catch (Exception e5) { 56 // try { 57 // return tryDeserialize(bytes, Response.class); 58 // } catch (Exception e6) { 59 // throw new SerializerException("Deserialize -> " + e6.getMessage(), 60 // e6); 61 // } 62 // } 63 // } 64 // } 65 // } 66 // } 67 // } 68 return null; 76 69 } 77 70
Note: See TracChangeset
for help on using the changeset viewer.