use of com.alipay.sofa.rpc.codec.sofahessian.serialize.CustomHessianSerializer in project sofa-rpc by sofastack.
the class SofaHessianSerializer method decode.
@Override
public Object decode(AbstractByteBuf data, Class clazz, Map<String, String> context) throws SofaRpcException {
if (clazz == null) {
throw buildDeserializeError("class is null!");
} else {
CustomHessianSerializer serializer = CustomHessianSerializerManager.getSerializer(clazz);
if (serializer != null) {
return serializer.decodeObject(data, context);
} else {
try {
UnsafeByteArrayInputStream inputStream = new UnsafeByteArrayInputStream(data.array());
Hessian2Input input = new Hessian2Input(inputStream);
input.setSerializerFactory(serializerFactory);
Object object = input.readObject();
input.close();
return object;
} catch (IOException e) {
throw buildDeserializeError(e.getMessage(), e);
}
}
}
}
use of com.alipay.sofa.rpc.codec.sofahessian.serialize.CustomHessianSerializer in project sofa-rpc by sofastack.
the class SofaHessianSerializer method encode.
@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);
}
}
}
Aggregations