Class EvolvableHandler
- java.lang.Object
-
- com.oracle.coherence.io.json.genson.reflect.EvolvableHandler
-
- All Implemented Interfaces:
UnknownPropertyHandler
public class EvolvableHandler extends Object implements UnknownPropertyHandler
An implementation of anUnknownPropertyHandlerthat supports evolution of data classes viaEvolvableinterface.If the target object we are deserializing into is
Evolvable, this handler will add any unknown properties encountered during deserialization intoEvolvable.unknownProperties()map, and will write them out along with all known properties during subsequent serialization.This prevents data loss when serializing and deserializing the same JSON payload using different versions of Java data classes.
- Author:
- Aleks Seovic 2018.05.20
-
-
Constructor Summary
Constructors Constructor Description EvolvableHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Consumer<T>readUnknownProperty(String propName, ObjectReader reader, Context ctx)Called whenever a property is encountered in a JSON document that doesn't have a correspondingPropertyMutator.<T> voidwriteUnknownProperties(T bean, ObjectWriter writer, Context ctx)Write unknown properties encountered during deserialization.
-
-
-
Method Detail
-
readUnknownProperty
public <T> Consumer<T> readUnknownProperty(String propName, ObjectReader reader, Context ctx)
Description copied from interface:UnknownPropertyHandlerCalled whenever a property is encountered in a JSON document that doesn't have a correspondingPropertyMutator.Typically, the implementation of this interface concerned with schema evolution will handle this event by storing property value somewhere so it can be written later by the
UnknownPropertyHandler.writeUnknownProperties(T, com.oracle.coherence.io.json.genson.stream.ObjectWriter, com.oracle.coherence.io.json.genson.Context)method.- Specified by:
readUnknownPropertyin interfaceUnknownPropertyHandler- Parameters:
propName- the name of the unknown propertyreader- the ObjectReader to read property value fromctx- deserialization context- Returns:
- the Consumer that will be called with the target bean, once the target bean is known
-
writeUnknownProperties
public <T> void writeUnknownProperties(T bean, ObjectWriter writer, Context ctx)Description copied from interface:UnknownPropertyHandlerWrite unknown properties encountered during deserialization.This method can be optionally implemented by
UnknownPropertyHandlers that want to write unknown properties during serialization. The default implementation is a no-op.- Specified by:
writeUnknownPropertiesin interfaceUnknownPropertyHandler- Parameters:
bean- the object we are serializing into JSONwriter- the ObjectReader to read property value fromctx- serialization context
-
-