Package de.aristaflow.ilm.util.jackson
Class DistFieldDeserialiser<F,F1 extends F,F2 extends F>
- java.lang.Object
-
- com.fasterxml.jackson.databind.JsonDeserializer<F>
-
- de.aristaflow.ilm.util.jackson.DistFieldDeserialiser<F,F1,F2>
-
- Type Parameters:
F- The deserialised type.F1- The more specific deserialised type in case the distinguishing field is not present.F2- The more specific deserialised type in case the distinguishing field is present.
- All Implemented Interfaces:
com.fasterxml.jackson.databind.deser.NullValueProvider
public abstract class DistFieldDeserialiser<F,F1 extends F,F2 extends F> extends com.fasterxml.jackson.databind.JsonDeserializer<F>This deserialiser chooses between two different class hierarchy based on the presence of a specific field (name).
-
-
Field Summary
Fields Modifier and Type Field Description protected StringdistFieldNameThe name of the field which distinguishes between deserialising either class hierarchy.protected Class<F1>root1The class of which to retrieve (sub-)instances of by using Jackson deserialisation ifdistFieldNameis not present.protected Class<F2>root2The filter class of which to retrieve (sub-)instances of by using Jackson deserialisation ifdistFieldNameis present.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Pair<Boolean,com.fasterxml.jackson.core.JsonParser>chooseSubtypeHierarchy(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt)Determines whether the designated stream has a field (at the current object) with thedistFieldNameby returning whether the field has been found.Fdeserialize(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt)ObjectdeserializeWithType(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt, com.fasterxml.jackson.databind.jsontype.TypeDeserializer typeDeserializer)-
Methods inherited from class com.fasterxml.jackson.databind.JsonDeserializer
deserialize, deserializeWithType, findBackReference, getAbsentValue, getDelegatee, getEmptyAccessPattern, getEmptyValue, getEmptyValue, getKnownPropertyNames, getNullAccessPattern, getNullValue, getNullValue, getObjectIdReader, handledType, isCachable, logicalType, replaceDelegatee, supportsUpdate, unwrappingDeserializer
-
-
-
-
Field Detail
-
root1
protected final Class<F1 extends F> root1
The class of which to retrieve (sub-)instances of by using Jackson deserialisation ifdistFieldNameis not present.
-
distFieldName
protected final String distFieldName
The name of the field which distinguishes between deserialising either class hierarchy.
-
root2
protected final Class<F2 extends F> root2
The filter class of which to retrieve (sub-)instances of by using Jackson deserialisation ifdistFieldNameis present.
-
-
Constructor Detail
-
DistFieldDeserialiser
protected DistFieldDeserialiser(Class<F1> root1, String distFieldName, Class<F2> root2)
Creates a new deserialiser for different class hierarchies distinguished via the presence of the designated field. If the designated field is present, instances ofroot2will be deserialised, otherwise instances ofroot1will be deserialised.- Parameters:
root1- The filter class of which to retrieve (sub-)instances of by using Jackson deserialisation ifdistFieldNameis not present.distFieldName- The name of the field which distinguishes between deserialising either class hierarchy.root2- The filter class of which to retrieve (sub-)instances of by using Jackson deserialisation ifdistFieldNameis present.
-
-
Method Detail
-
chooseSubtypeHierarchy
protected Pair<Boolean,com.fasterxml.jackson.core.JsonParser> chooseSubtypeHierarchy(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt) throws IOException
Determines whether the designated stream has a field (at the current object) with thedistFieldNameby returning whether the field has been found.- Parameters:
p- The parser providing the JSON.ctxt- The context in which to deserialise from the designated JSON (parser).- Returns:
- Whether the
distFieldNamehas been found or not and the designated JSON parser wrapped and positioned at the position when calling this method. - Throws:
IOException- If there are problems reading from the designated JSON (parser), anIOExceptionwill be thrown.
-
deserialize
public F deserialize(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt) throws IOException
- Specified by:
deserializein classcom.fasterxml.jackson.databind.JsonDeserializer<F>- Throws:
IOException
-
deserializeWithType
public Object deserializeWithType(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.databind.DeserializationContext ctxt, com.fasterxml.jackson.databind.jsontype.TypeDeserializer typeDeserializer) throws IOException
- Overrides:
deserializeWithTypein classcom.fasterxml.jackson.databind.JsonDeserializer<F>- Throws:
IOException
-
-