Class JsonInstanceSerializer<T>
- java.lang.Object
-
- org.apache.curator.x.discovery.details.JsonInstanceSerializer<T>
-
- All Implemented Interfaces:
InstanceSerializer<T>
public class JsonInstanceSerializer<T> extends java.lang.Object implements InstanceSerializer<T>
A serializer that uses Jackson to serialize/deserialize as JSON. IMPORTANT: The instance payload must support Jackson
-
-
Constructor Summary
Constructors Constructor Description JsonInstanceSerializer(java.lang.Class<T> payloadClass)
CURATOR-275 introduced a new field intoServiceInstance
.JsonInstanceSerializer(java.lang.Class<T> payloadClass, boolean compatibleSerializationMode)
CURATOR-275 introduced a new field intoServiceInstance
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ServiceInstance<T>
deserialize(byte[] bytes)
Deserialize a byte array into an instancebyte[]
serialize(ServiceInstance<T> instance)
Serialize an instance into bytes
-
-
-
Constructor Detail
-
JsonInstanceSerializer
public JsonInstanceSerializer(java.lang.Class<T> payloadClass)
CURATOR-275 introduced a new field intoServiceInstance
. This caused a potentialUnrecognizedPropertyException
in older clients that read newly serialized ServiceInstances. Therefore the default behavior of JsonInstanceSerializer has been changed to NOT serialize theenabled
field. If you wish to use that field, use the alternate constructorJsonInstanceSerializer(Class, boolean)
and pass true forcompatibleSerializationMode
. Note: future versions of Curator may change this behavior.- Parameters:
payloadClass
- used to validate payloads when deserializing
-
JsonInstanceSerializer
public JsonInstanceSerializer(java.lang.Class<T> payloadClass, boolean compatibleSerializationMode)
CURATOR-275 introduced a new field intoServiceInstance
. This caused a potentialUnrecognizedPropertyException
in older clients that read newly serialized ServiceInstances. If you are susceptible to this you should set the serializer to be an instance ofJsonInstanceSerializer
withcompatibleSerializationMode
set to true. IMPORTANT: when this is done, the newenabled
field of ServiceInstance is not serialized. If however you do want to use theenabled
field, setcompatibleSerializationMode
to false.- Parameters:
payloadClass
- used to validate payloads when deserializingcompatibleSerializationMode
- pass true to serialize in a manner that supports clients pre-CURATOR-275
-
-
Method Detail
-
deserialize
public ServiceInstance<T> deserialize(byte[] bytes) throws java.lang.Exception
Description copied from interface:InstanceSerializer
Deserialize a byte array into an instance- Specified by:
deserialize
in interfaceInstanceSerializer<T>
- Parameters:
bytes
- the bytes- Returns:
- service instance
- Throws:
java.lang.Exception
- any errors
-
serialize
public byte[] serialize(ServiceInstance<T> instance) throws java.lang.Exception
Description copied from interface:InstanceSerializer
Serialize an instance into bytes- Specified by:
serialize
in interfaceInstanceSerializer<T>
- Parameters:
instance
- the instance- Returns:
- byte array representing the instance
- Throws:
java.lang.Exception
- any errors
-
-