@Test public void encode() { AbstractByteBuf data = serializer.encode("xxx", null); String dst = (String) serializer.decode(data, String.class, null); Assert.assertEquals("xxx", dst); boolean error = false; try { serializer.decode(data, "", null); } catch (Exception e) { error = true; } Assert.assertTrue(error); error = false; try { serializer.decode(data, null, null); } catch (Exception e) { error = true; } Assert.assertTrue(error); error = false; try { serializer.decode(data, (Object) null, null); } catch (Exception e) { error = true; } Assert.assertTrue(error); }
@Override public AbstractByteBuf encode(Object object, Map<String, String> context) { CustomHessianSerializer serializer = getCustomSerializer(object); if (serializer != null) { return serializer.encodeObject(object, context); } else { UnsafeByteArrayOutputStream byteArray = new UnsafeByteArrayOutputStream(); Hessian2Output output = new Hessian2Output(byteArray); try { output.setSerializerFactory(serializerFactory); output.writeObject(object); output.close(); return new ByteStreamWrapperByteBuf(byteArray); } catch (Exception e) { throw buildSerializeError(e.getMessage(), e); } } }
SofaHessianSerializer extends AbstractSerializer { @Override public AbstractByteBuf encode(Object object, Map<String, String> context) { CustomHessianSerializer serializer = getCustomSerializer(object); if (serializer != null) { return serializer.encodeObject(object, context); } else { UnsafeByteArrayOutputStream byteArray = new UnsafeByteArrayOutputStream(); Hessian2Output output = new Hessian2Output(byteArray); try { output.setSerializerFactory(serializerFactory); output.writeObject(object); output.close(); return new ByteStreamWrapperByteBuf(byteArray); } catch (Exception e) { throw buildSerializeError(e.getMessage(), e); } } } }
SofaHessianSerializer extends AbstractSerializer { @Override public AbstractByteBuf encode(Object object, Map<String, String> context) { CustomHessianSerializer serializer = getCustomSerializer(object); if (serializer != null) { return serializer.encodeObject(object, context); } else { UnsafeByteArrayOutputStream byteArray = new UnsafeByteArrayOutputStream(); Hessian2Output output = new Hessian2Output(byteArray); try { output.setSerializerFactory(serializerFactory); output.writeObject(object); output.close(); return new ByteStreamWrapperByteBuf(byteArray); } catch (Exception e) { throw buildSerializeError(e.getMessage(), e); } } } SofaHessianSerializer(); }
SofaHessianSerializer extends AbstractSerializer { @Override public AbstractByteBuf encode(Object object, Map<String, String> context) { CustomHessianSerializer serializer = getCustomSerializer(object); if (serializer != null) { return serializer.encodeObject(object, context); } else { UnsafeByteArrayOutputStream byteArray = new UnsafeByteArrayOutputStream(); Hessian2Output output = new Hessian2Output(byteArray); try { output.setSerializerFactory(serializerFactory); output.writeObject(object); output.close(); return new ByteStreamWrapperByteBuf(byteArray); } catch (Exception e) { throw buildSerializeError(e.getMessage(), e); } } } SofaHessianSerializer(); @Override AbstractByteBuf encode(Object object, Map<String, String> context); @Override Object decode(AbstractByteBuf data, Class clazz, Map<String, String> context); @Override void decode(AbstractByteBuf data, Object template, Map<String, String> context); }
SofaHessianSerializer extends AbstractSerializer { @Override public AbstractByteBuf encode(Object object, Map<String, String> context) { CustomHessianSerializer serializer = getCustomSerializer(object); if (serializer != null) { return serializer.encodeObject(object, context); } else { UnsafeByteArrayOutputStream byteArray = new UnsafeByteArrayOutputStream(); Hessian2Output output = new Hessian2Output(byteArray); try { output.setSerializerFactory(serializerFactory); output.writeObject(object); output.close(); return new ByteStreamWrapperByteBuf(byteArray); } catch (Exception e) { throw buildSerializeError(e.getMessage(), e); } } } SofaHessianSerializer(); @Override AbstractByteBuf encode(Object object, Map<String, String> context); @Override Object decode(AbstractByteBuf data, Class clazz, Map<String, String> context); @Override void decode(AbstractByteBuf data, Object template, Map<String, String> context);  }