3131/**
3232 * Serializes and deserializes an internal object.
3333 */
34- public class ObjectSerializer {
34+ public abstract class ExtensionObjectSerializer extends AbstractObjectSerializer {
3535
3636 /**
3737 * Shared Json serializer/deserializer as per Jackson's documentation.
@@ -44,7 +44,7 @@ public class ObjectSerializer {
4444 /**
4545 * Default constructor to avoid class from being instantiated outside package but still inherited.
4646 */
47- protected ObjectSerializer () {
47+ protected ExtensionObjectSerializer () {
4848 }
4949
5050 /**
@@ -55,33 +55,31 @@ protected ObjectMapper getObjectMapper() {
5555 }
5656
5757 /**
58- * Serializes a given state object into byte array.
58+ * Serializes a given object into byte array.
5959 *
60- * @param state State object to be serialized.
60+ * @param o object to be serialized.
6161 * @return Array of bytes[] with the serialized content.
62- * @throws IOException In case state cannot be serialized.
62+ * @throws IOException In case o cannot be serialized.
6363 */
64- public byte [] serialize (Object state ) throws IOException {
65- if (state == null ) {
64+ @ Override
65+ public byte [] doSerialize (Object o ) throws IOException {
66+ if (o == null ) {
6667 return null ;
6768 }
68-
69- if (state .getClass () == Void .class ) {
69+ if (o .getClass () == Void .class ) {
7070 return null ;
7171 }
72-
7372 // Have this check here to be consistent with deserialization (see deserialize() method below).
74- if (state instanceof byte []) {
75- return (byte []) state ;
73+ if (o instanceof byte []) {
74+ return (byte []) o ;
7675 }
77-
7876 // Proto buffer class is serialized directly.
79- if (state instanceof MessageLite ) {
80- return ((MessageLite ) state ).toByteArray ();
77+ if (o instanceof MessageLite ) {
78+ return ((MessageLite ) o ).toByteArray ();
8179 }
8280
8381 // Not string, not primitive, so it is a complex type: we use JSON for that.
84- return getObjectMapper ().writeValueAsBytes (state );
82+ return getObjectMapper ().writeValueAsBytes (o );
8583 }
8684
8785 /**
@@ -93,8 +91,9 @@ public byte[] serialize(Object state) throws IOException {
9391 * @return Object of type T.
9492 * @throws IOException In case content cannot be deserialized.
9593 */
96- public <T > T deserialize (byte [] content , TypeRef <T > type ) throws IOException {
97- return deserialize (content , getObjectMapper ().constructType (type .getType ()));
94+ @ Override
95+ public <T > T doDeserialize (byte [] content , TypeRef <T > type ) throws IOException {
96+ return doDeserialize (content , getObjectMapper ().constructType (type .getType ()));
9897 }
9998
10099 /**
@@ -106,11 +105,11 @@ public <T> T deserialize(byte[] content, TypeRef<T> type) throws IOException {
106105 * @return Object of type T.
107106 * @throws IOException In case content cannot be deserialized.
108107 */
109- public <T > T deserialize (byte [] content , Class <T > clazz ) throws IOException {
110- return deserialize (content , getObjectMapper ().constructType (clazz ));
108+ public <T > T doDeserialize (byte [] content , Class <T > clazz ) throws IOException {
109+ return doDeserialize (content , getObjectMapper ().constructType (clazz ));
111110 }
112111
113- private <T > T deserialize (byte [] content , JavaType javaType ) throws IOException {
112+ private <T > T doDeserialize (byte [] content , JavaType javaType ) throws IOException {
114113 if ((javaType == null ) || javaType .isTypeOrSubTypeOf (Void .class )) {
115114 return null ;
116115 }
0 commit comments