Class SerializerProvider
- Direct Known Subclasses:
DefaultSerializerProvider
ObjectMapper
and
JsonSerializer
s to obtain serializers capable of serializing
instances of specific types; as well as the default implementation
of the functionality.
Provider handles caching aspects of serializer handling; all construction
details are delegated to SerializerFactory
instance.
Object life-cycle is such that an initial instance ("blueprint") is created
and referenced by ObjectMapper
and ObjectWriter
intances;
but for actual usage, a configured instance is created by using
a create method in sub-class
DefaultSerializerProvider
.
Only this instance can be used for actual serialization calls; blueprint
object is only to be used for creating instances.
-
Field Summary
Modifier and TypeFieldDescriptionprotected ContextAttributes
Lazily-constructed holder for per-call attributes.protected final SerializationConfig
Serialization configuration to use for serialization processing.protected DateFormat
Lazily acquired and instantiated formatter object: initialized first time it is needed, reused afterwards.protected JsonSerializer<Object>
Serializer used to output non-null keys of Maps (which will get output as JSON Objects), if not null; if null, us the standard default key serializer.protected final ReadOnlyClassToSerializerMap
For fast lookups, we will have a local non-shared read-only map that contains serializers previously fetched.protected JsonSerializer<Object>
Serializer used to (try to) output a null key, due to an entry ofMap
having null key.protected JsonSerializer<Object>
Serializer used to output a null value.protected final Class<?>
View used for currently active serialization, if any.protected final SerializerCache
Cache for doing type-to-value-serializer lookups.protected final SerializerFactory
Factory used for constructing actual serializer instances.protected final boolean
Flag set to indicate that we are using vanilla null value serializationprotected JsonSerializer<Object>
Serializer that gets called for values of types for which no serializers can be constructed.protected static final boolean
Setting for determining whether mappings for "unknown classes" should be cached for faster resolution.static final JsonSerializer<Object>
protected static final JsonSerializer<Object>
Placeholder serializer used whenjava.lang.Object
typed property is marked to be serialized. -
Constructor Summary
ModifierConstructorDescriptionConstructor for creating master (or "blue-print") provider object, which is only used as the template for constructing per-binding instances.protected
Copy-constructor used when making a copy of a blueprint instance.protected
SerializerProvider
(SerializerProvider src, SerializationConfig config, SerializerFactory f) "Copy-constructor", used by sub-classes when creating actual non-blueprint instances to use. -
Method Summary
Modifier and TypeMethodDescriptionprotected JsonSerializer<Object>
protected JsonSerializer<Object>
_createAndCacheUntypedSerializer
(Class<?> rawType) Method that will try to construct a value serializer; and if one is successfully created, cache it for reuse.protected JsonSerializer<Object>
protected final DateFormat
protected JsonSerializer<Object>
_findExplicitUntypedSerializer
(Class<?> runtimeType) Method that will try to find a serializer, either from cache or by constructing one; but will not return an "unknown" serializer if this cannot be done but rather returns null.protected JsonSerializer<Object>
_handleContextualResolvable
(JsonSerializer<?> ser, BeanProperty property) Helper method called to resolve and contextualize given serializer, if and as necessary.protected JsonSerializer<Object>
_handleResolvable
(JsonSerializer<?> ser) protected void
_reportIncompatibleRootType
(Object value, JavaType rootType) final TokenBuffer
Specialized factory method used when we are converting values and do not typically have or use "real" parsers or generators.Specialized factory method used when we are converting values and do not typically have or use "real" parsers or generators.final boolean
Convenience method for accessing serialization view in use (if any); equivalent to:constructSpecializedType
(JavaType baseType, Class<?> subclass) Convenience method for constructing subtypes, retaining generic type parameter (if any).void
defaultSerializeDateKey
(long timestamp, JsonGenerator gen) Method that will handle serialization of Dates used asMap
keys, based onSerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS
value (and if using textual representation, configured date format)void
defaultSerializeDateKey
(Date date, JsonGenerator gen) Method that will handle serialization of Dates used asMap
keys, based onSerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS
value (and if using textual representation, configured date format)final void
defaultSerializeDateValue
(long timestamp, JsonGenerator gen) Method that will handle serialization of Date(-like) values, usingSerializationConfig
settings to determine expected serialization behavior.final void
defaultSerializeDateValue
(Date date, JsonGenerator gen) Method that will handle serialization of Date(-like) values, usingSerializationConfig
settings to determine expected serialization behavior.final void
defaultSerializeField
(String fieldName, Object value, JsonGenerator gen) Convenience method that will serialize given field with specified value.final void
final void
defaultSerializeValue
(Object value, JsonGenerator gen) Convenience method that will serialize given value (which can be null) using standard serializer locating functionality.findContentValueSerializer
(JavaType valueType, BeanProperty property) Alternative tofindPrimaryPropertySerializer(JavaType, BeanProperty)
called not for primary value, but "content" of such primary serializer: element of an array orCollection
, value ofMap
entry and so on.findContentValueSerializer
(Class<?> valueType, BeanProperty property) findKeySerializer
(JavaType keyType, BeanProperty property) Method called to get the serializer to use for serializing non-null Map keys.findKeySerializer
(Class<?> rawKeyType, BeanProperty property) findNullKeySerializer
(JavaType serializationType, BeanProperty property) Method called to find a serializer to use for null values for given declared type.findNullValueSerializer
(BeanProperty property) Method called to get the serializer to use for serializing null values for specified property.abstract WritableObjectId
findObjectId
(Object forPojo, ObjectIdGenerator<?> generatorType) Method called to find the Object Id for given POJO, if one has been generated.findPrimaryPropertySerializer
(JavaType valueType, BeanProperty property) Similar tofindValueSerializer(JavaType, BeanProperty)
, but used when finding "primary" property value serializer (one directly handling value of the property).findPrimaryPropertySerializer
(Class<?> valueType, BeanProperty property) findTypedValueSerializer
(JavaType valueType, boolean cache, BeanProperty property) Method called to locate regular serializer, matching type serializer, and if both found, wrap them in a serializer that calls both in correct sequence.findTypedValueSerializer
(Class<?> valueType, boolean cache, BeanProperty property) Method called to locate regular serializer, matching type serializer, and if both found, wrap them in a serializer that calls both in correct sequence.findTypeSerializer
(JavaType javaType) Method called to get theTypeSerializer
to use for including Type Id necessary for serializing for the given Java class.findValueSerializer
(JavaType valueType) Method variant used when we do NOT want contextualization to happen; it will need to be handled at a later point, but caller wants to be able to do that as needed; sometimes to avoid infinite loopsfindValueSerializer
(JavaType valueType, BeanProperty property) Similar tofindValueSerializer(Class,BeanProperty)
, but takes full generics-aware type instead of raw class.findValueSerializer
(Class<?> valueType) Method variant used when we do NOT want contextualization to happen; it will need to be handled at a later point, but caller wants to be able to do that as needed; sometimes to avoid infinite loopsfindValueSerializer
(Class<?> valueType, BeanProperty property) Method called to get hold of a serializer for a value of given type; or if no such serializer can be found, a default handler (which may do a best-effort generic serialization or just simply throw an exception when invoked).final Class<?>
Accessor for locating currently active view, if any; returns null if no view has been set.final AnnotationIntrospector
Convenience method for accessing serialization view in use (if any); equivalent to:getAttribute
(Object key) Method for accessing attributes available in this context.final SerializationConfig
Method for accessing configuration for the serialization processing.final JsonFormat.Value
getDefaultPropertyFormat
(Class<?> baseType) final JsonInclude.Value
getDefaultPropertyInclusion
(Class<?> baseType) final FilterProvider
Convenience method for accessing provider to find serialization filters used, equivalent to calling:NOTE: current implementation simply returns `null` as generator is not yet assigned to this provider.Method for accessing default Locale to use: convenience method forMethod for accessing default TimeZone to use: convenience method forfinal TypeFactory
getUnknownTypeSerializer
(Class<?> unknownType) Method called to get the serializer to use if provider cannot determine an actual type-specific serializer to use; typically when none ofSerializerFactory
instances are able to construct a serializer.handlePrimaryContextualization
(JsonSerializer<?> ser, BeanProperty property) Method called for primary property serializers (ones directly created to serialize values of a POJO property), to handle details of resolvingContextualSerializer
with given property context.handleSecondaryContextualization
(JsonSerializer<?> ser, BeanProperty property) Method called for secondary property serializers (ones NOT directly created to serialize values of a POJO property but instead created as a dependant serializer -- such as value serializers for structured types, or serializers for root values) to handle details of resolvingContextualDeserializer
with given property context.final boolean
hasSerializationFeatures
(int featureMask) "Bulk" access method for checking that all features specified by mask are enabled.abstract Object
includeFilterInstance
(BeanPropertyDefinition forProperty, Class<?> filterClass) Method that can be called to construct and configureJsonInclude
filter instance, given aClass
to instantiate (with default constructor, by default).abstract boolean
includeFilterSuppressNulls
(Object filter) Follow-up method that may be called after callingincludeFilterInstance(edu.internet2.middleware.grouperClientExt.com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition, java.lang.Class<?>)
, to check handling of `null` values by the filter.invalidTypeIdException
(JavaType baseType, String typeId, String extraDesc) Helper method for constructing exception to indicate that given type id could not be resolved to a valid subtype of specified base type.final boolean
isEnabled
(DatatypeFeature feature) Method for checking whether specified datatype feature is enabled or not.final boolean
isEnabled
(MapperFeature feature) Convenience method for checking whether specified Mapper feature is enabled or not.final boolean
isEnabled
(SerializationFeature feature) Convenience method for checking whether specified serialization feature is enabled or not.boolean
Helper method called to see if given serializer is considered to be something returned bygetUnknownTypeSerializer(java.lang.Class<?>)
, that is, something for which no regular serializer was found or constructed.mappingException
(String message, Object... msgArgs) Deprecated.Since 2.9protected JsonMappingException
mappingException
(Throwable t, String message, Object... msgArgs) Deprecated.Since 2.9<T> T
reportBadDefinition
(JavaType type, String msg) Helper method called to indicate a generic problem that stems from type definition(s), not input data, or input/output state; typically this means throwing aInvalidDefinitionException
.<T> T
reportBadDefinition
(JavaType type, String msg, Throwable cause) <T> T
reportBadDefinition
(Class<?> raw, String msg, Throwable cause) <T> T
reportBadPropertyDefinition
(BeanDescription bean, BeanPropertyDefinition prop, String message, Object... msgArgs) Helper method called to indicate problem in POJO (serialization) definitions or settings regarding specific property (of a type), unrelated to actual JSON content to map.<T> T
reportBadTypeDefinition
(BeanDescription bean, String msg, Object... msgArgs) Helper method called to indicate problem in POJO (serialization) definitions or settings regarding specific Java type, unrelated to actual JSON content to map.void
reportMappingProblem
(String message, Object... args) Helper method called to indicate problem; default behavior is to construct and throw aJsonMappingException
, but in future may collect more than one and only throw after certain number, or at the end of serialization.void
reportMappingProblem
(Throwable t, String message, Object... msgArgs) Helper method called to indicate problem; default behavior is to construct and throw aJsonMappingException
, but in future may collect more than one and only throw after certain number, or at the end of serialization.abstract JsonSerializer<Object>
serializerInstance
(Annotated annotated, Object serDef) Method that can be called to construct and configure serializer instance, either given aClass
to instantiate (with default constructor), or an uninitialized serializer instance.setAttribute
(Object key, Object value) Method for setting per-call value of given attribute.void
Method that can be used to specify serializer to use for serializing all non-null JSON property names, unless more specific key serializer is found (i.e.void
Method that can be used to specify serializer that will be used to write JSON property names matching null keys for Java Maps (which will otherwise throw an exception if try write such property name)void
Method that can be used to specify serializer that will be used to write JSON values matching Java null values instead of default one (which simply writes JSON null).Methods inherited from class edu.internet2.middleware.grouperClientExt.com.fasterxml.jackson.databind.DatabindContext
_colonConcat, _desc, _format, _quotedString, _throwNotASubtype, _throwSubtypeClassNotAllowed, _throwSubtypeNameNotAllowed, _truncate, constructType, converterInstance, objectIdGeneratorInstance, objectIdResolverInstance, reportBadDefinition, resolveAndValidateSubType, resolveSubType
-
Field Details
-
CACHE_UNKNOWN_MAPPINGS
protected static final boolean CACHE_UNKNOWN_MAPPINGSSetting for determining whether mappings for "unknown classes" should be cached for faster resolution. Usually this isn't needed, but maybe it is in some cases?- See Also:
-
DEFAULT_NULL_KEY_SERIALIZER
-
DEFAULT_UNKNOWN_SERIALIZER
Placeholder serializer used whenjava.lang.Object
typed property is marked to be serialized.
NOTE: starting with 2.6, this instance is NOT used for any other types, and separate instances are constructed for "empty" Beans.NOTE: changed to
protected
for 2.3; no need to be publicly available. -
_config
Serialization configuration to use for serialization processing. -
_serializationView
View used for currently active serialization, if any. Only set for non-blueprint instances. -
_serializerFactory
Factory used for constructing actual serializer instances. Only set for non-blueprint instances. -
_serializerCache
Cache for doing type-to-value-serializer lookups. -
_attributes
Lazily-constructed holder for per-call attributes. Only set for non-blueprint instances.- Since:
- 2.3
-
_unknownTypeSerializer
Serializer that gets called for values of types for which no serializers can be constructed.The default serializer will simply thrown an exception.
-
_keySerializer
Serializer used to output non-null keys of Maps (which will get output as JSON Objects), if not null; if null, us the standard default key serializer. -
_nullValueSerializer
Serializer used to output a null value. Default implementation writes nulls usingJsonGenerator.writeNull()
. -
_nullKeySerializer
Serializer used to (try to) output a null key, due to an entry ofMap
having null key. The default implementation will throw an exception if this happens; alternative implementation (like one that would write an Empty String) can be defined. -
_knownSerializers
For fast lookups, we will have a local non-shared read-only map that contains serializers previously fetched. -
_dateFormat
Lazily acquired and instantiated formatter object: initialized first time it is needed, reused afterwards. Used via instances (not blueprints), so that access need not be thread-safe. -
_stdNullValueSerializer
protected final boolean _stdNullValueSerializerFlag set to indicate that we are using vanilla null value serialization- Since:
- 2.3
-
-
Constructor Details
-
SerializerProvider
public SerializerProvider()Constructor for creating master (or "blue-print") provider object, which is only used as the template for constructing per-binding instances. -
SerializerProvider
protected SerializerProvider(SerializerProvider src, SerializationConfig config, SerializerFactory f) "Copy-constructor", used by sub-classes when creating actual non-blueprint instances to use.- Parameters:
src
- Blueprint object used as the baseline for this instance
-
SerializerProvider
Copy-constructor used when making a copy of a blueprint instance.- Since:
- 2.5
-
-
Method Details
-
setDefaultKeySerializer
Method that can be used to specify serializer to use for serializing all non-null JSON property names, unless more specific key serializer is found (i.e. if not custom key serializer has been registered for Java type).Note that key serializer registration are different from value serializer registrations.
-
setNullValueSerializer
Method that can be used to specify serializer that will be used to write JSON values matching Java null values instead of default one (which simply writes JSON null).Note that you can get finer control over serializer to use by overriding
findNullValueSerializer(edu.internet2.middleware.grouperClientExt.com.fasterxml.jackson.databind.BeanProperty)
, which gets called once per each property. -
setNullKeySerializer
Method that can be used to specify serializer that will be used to write JSON property names matching null keys for Java Maps (which will otherwise throw an exception if try write such property name) -
getConfig
Method for accessing configuration for the serialization processing.- Specified by:
getConfig
in classDatabindContext
-
getAnnotationIntrospector
Description copied from class:DatabindContext
Convenience method for accessing serialization view in use (if any); equivalent to:getConfig().getAnnotationIntrospector();
- Specified by:
getAnnotationIntrospector
in classDatabindContext
-
getTypeFactory
- Specified by:
getTypeFactory
in classDatabindContext
-
constructSpecializedType
public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass) throws IllegalArgumentException Description copied from class:DatabindContext
Convenience method for constructing subtypes, retaining generic type parameter (if any).Note: since 2.11 handling has varied a bit across serialization, deserialization.
- Specified by:
constructSpecializedType
in classDatabindContext
- Throws:
IllegalArgumentException
-
getActiveView
Description copied from class:DatabindContext
Accessor for locating currently active view, if any; returns null if no view has been set.- Specified by:
getActiveView
in classDatabindContext
-
canOverrideAccessModifiers
public final boolean canOverrideAccessModifiers()Description copied from class:DatabindContext
Convenience method for accessing serialization view in use (if any); equivalent to:getConfig().canOverrideAccessModifiers();
- Specified by:
canOverrideAccessModifiers
in classDatabindContext
-
isEnabled
Description copied from class:DatabindContext
Convenience method for checking whether specified Mapper feature is enabled or not. Shortcut for:getConfig().isEnabled(feature);
- Specified by:
isEnabled
in classDatabindContext
-
isEnabled
Description copied from class:DatabindContext
Method for checking whether specified datatype feature is enabled or not.- Specified by:
isEnabled
in classDatabindContext
-
getDefaultPropertyFormat
- Specified by:
getDefaultPropertyFormat
in classDatabindContext
-
getDefaultPropertyInclusion
- Since:
- 2.8
-
getLocale
Method for accessing default Locale to use: convenience method forgetConfig().getLocale();
- Specified by:
getLocale
in classDatabindContext
-
getTimeZone
Method for accessing default TimeZone to use: convenience method forgetConfig().getTimeZone();
- Specified by:
getTimeZone
in classDatabindContext
-
getAttribute
Description copied from class:DatabindContext
Method for accessing attributes available in this context. Per-call attributes have highest precedence; attributes set viaObjectReader
orObjectWriter
have lower precedence.- Specified by:
getAttribute
in classDatabindContext
- Parameters:
key
- Key of the attribute to get- Returns:
- Value of the attribute, if any; null otherwise
-
setAttribute
Description copied from class:DatabindContext
Method for setting per-call value of given attribute. This will override any previously defined value for the attribute within this context.- Specified by:
setAttribute
in classDatabindContext
- Parameters:
key
- Key of the attribute to setvalue
- Value to set attribute to- Returns:
- This context object, to allow chaining
-
isEnabled
Convenience method for checking whether specified serialization feature is enabled or not. Shortcut for:getConfig().isEnabled(feature);
-
hasSerializationFeatures
public final boolean hasSerializationFeatures(int featureMask) "Bulk" access method for checking that all features specified by mask are enabled.- Since:
- 2.3
-
getFilterProvider
Convenience method for accessing provider to find serialization filters used, equivalent to calling:getConfig().getFilterProvider();
-
getGenerator
NOTE: current implementation simply returns `null` as generator is not yet assigned to this provider.
- Since:
- 2.8
-
bufferForValueConversion
Specialized factory method used when we are converting values and do not typically have or use "real" parsers or generators.- Since:
- 2.13
-
bufferForValueConversion
Specialized factory method used when we are converting values and do not typically have or use "real" parsers or generators.- Since:
- 2.13
-
findObjectId
Method called to find the Object Id for given POJO, if one has been generated. Will always return a non-null Object; contents vary depending on whether an Object Id already exists or not. -
findValueSerializer
public JsonSerializer<Object> findValueSerializer(Class<?> valueType, BeanProperty property) throws JsonMappingException Method called to get hold of a serializer for a value of given type; or if no such serializer can be found, a default handler (which may do a best-effort generic serialization or just simply throw an exception when invoked).Note: this method is only called for non-null values; not for keys or null values. For these, check out other accessor methods.
Note that serializers produced should NOT handle polymorphic serialization aspects; separate
TypeSerializer
is to be constructed by caller if and as necessary.- Throws:
JsonMappingException
- if there are fatal problems with accessing suitable serializer; including that of not finding any serializer
-
findValueSerializer
public JsonSerializer<Object> findValueSerializer(JavaType valueType, BeanProperty property) throws JsonMappingException Similar tofindValueSerializer(Class,BeanProperty)
, but takes full generics-aware type instead of raw class. This is necessary for accurate handling of external type information, to handle polymorphic types.Note: this call will also contextualize serializer before returning it.
- Parameters:
property
- When creating secondary serializers, property for which serializer is needed: annotations of the property (or bean that contains it) may be checked to create contextual serializers.- Throws:
JsonMappingException
-
findValueSerializer
Method variant used when we do NOT want contextualization to happen; it will need to be handled at a later point, but caller wants to be able to do that as needed; sometimes to avoid infinite loops- Throws:
JsonMappingException
- Since:
- 2.5
-
findValueSerializer
Method variant used when we do NOT want contextualization to happen; it will need to be handled at a later point, but caller wants to be able to do that as needed; sometimes to avoid infinite loops- Throws:
JsonMappingException
- Since:
- 2.5
-
findPrimaryPropertySerializer
public JsonSerializer<Object> findPrimaryPropertySerializer(JavaType valueType, BeanProperty property) throws JsonMappingException Similar tofindValueSerializer(JavaType, BeanProperty)
, but used when finding "primary" property value serializer (one directly handling value of the property). Difference has to do with contextual resolution, and method(s) called: this method should only be called when caller is certain that this is the primary property value serializer.- Parameters:
valueType
- Type of values to serializeproperty
- Property that is being handled; will never be null, and its type has to matchvalueType
parameter.- Throws:
JsonMappingException
- Since:
- 2.3
-
findPrimaryPropertySerializer
public JsonSerializer<Object> findPrimaryPropertySerializer(Class<?> valueType, BeanProperty property) throws JsonMappingException - Throws:
JsonMappingException
- Since:
- 2.3
-
findContentValueSerializer
public JsonSerializer<Object> findContentValueSerializer(JavaType valueType, BeanProperty property) throws JsonMappingException Alternative tofindPrimaryPropertySerializer(JavaType, BeanProperty)
called not for primary value, but "content" of such primary serializer: element of an array orCollection
, value ofMap
entry and so on. This means thatproperty
passed (if any) does NOT represent value for which serializer is requested but its secondary type (or secondary type of that type, recursively).Serializer returned SHOULD NOT handle type information; caller will (have to) add suitable wrapping if necessary.
Note: this call will also contextualize serializer (call
createContextual()
before returning it, if applicable (implementsContextualSerializer
)- Parameters:
valueType
- Type of values to serializeproperty
- Property that indirectly refers to value being serialized (optional, may benull
for root level serializers)- Throws:
JsonMappingException
- Since:
- 2.11
-
findContentValueSerializer
public JsonSerializer<Object> findContentValueSerializer(Class<?> valueType, BeanProperty property) throws JsonMappingException - Throws:
JsonMappingException
- Since:
- 2.11
-
findTypedValueSerializer
public JsonSerializer<Object> findTypedValueSerializer(Class<?> valueType, boolean cache, BeanProperty property) throws JsonMappingException Method called to locate regular serializer, matching type serializer, and if both found, wrap them in a serializer that calls both in correct sequence. This method is currently only used for root-level serializer handling to allow for simpler caching. A call can always be replaced by equivalent calls to access serializer and type serializer separately.- Parameters:
valueType
- Type for purpose of locating a serializer; usually dynamic runtime type, but can also be static declared type, depending on configurationcache
- Whether resulting value serializer should be cached or not; this is just a hintproperty
- When creating secondary serializers, property for which serializer is needed: annotations of the property (or bean that contains it) may be checked to create contextual serializers.- Throws:
JsonMappingException
-
findTypedValueSerializer
public JsonSerializer<Object> findTypedValueSerializer(JavaType valueType, boolean cache, BeanProperty property) throws JsonMappingException Method called to locate regular serializer, matching type serializer, and if both found, wrap them in a serializer that calls both in correct sequence. This method is currently only used for root-level serializer handling to allow for simpler caching. A call can always be replaced by equivalent calls to access serializer and type serializer separately.- Parameters:
valueType
- Declared type of value being serialized (which may not be actual runtime type); used for finding both value serializer and type serializer to use for adding polymorphic type (if any)cache
- Whether resulting value serializer should be cached or not; this is just a hintproperty
- When creating secondary serializers, property for which serializer is needed: annotations of the property (or bean that contains it) may be checked to create contextual serializers.- Throws:
JsonMappingException
-
findTypeSerializer
Method called to get theTypeSerializer
to use for including Type Id necessary for serializing for the given Java class. Useful for schema generators.- Throws:
JsonMappingException
- Since:
- 2.6
-
findKeySerializer
public JsonSerializer<Object> findKeySerializer(JavaType keyType, BeanProperty property) throws JsonMappingException Method called to get the serializer to use for serializing non-null Map keys. Separation from regularfindValueSerializer(java.lang.Class<?>, edu.internet2.middleware.grouperClientExt.com.fasterxml.jackson.databind.BeanProperty)
method is because actual write method must be different (@link JsonGenerator#writeFieldName}; but also since behavior for some key types may differ.Note that the serializer itself can be called with instances of any Java object, but not nulls.
- Throws:
JsonMappingException
-
findKeySerializer
public JsonSerializer<Object> findKeySerializer(Class<?> rawKeyType, BeanProperty property) throws JsonMappingException - Throws:
JsonMappingException
- Since:
- 2.7
-
getDefaultNullKeySerializer
- Since:
- 2.0
-
getDefaultNullValueSerializer
- Since:
- 2.0
-
findNullKeySerializer
public JsonSerializer<Object> findNullKeySerializer(JavaType serializationType, BeanProperty property) throws JsonMappingException Method called to find a serializer to use for null values for given declared type. Note that type is completely based on declared type, since nulls in Java have no type and thus runtime type cannot be determined.- Throws:
JsonMappingException
- Since:
- 2.0
-
findNullValueSerializer
public JsonSerializer<Object> findNullValueSerializer(BeanProperty property) throws JsonMappingException Method called to get the serializer to use for serializing null values for specified property.Default implementation simply calls
getDefaultNullValueSerializer()
; can be overridden to add custom null serialization for properties of certain type or name. This gives method full granularity to basically override null handling for any specific property or class of properties.- Throws:
JsonMappingException
- Since:
- 2.0
-
getUnknownTypeSerializer
Method called to get the serializer to use if provider cannot determine an actual type-specific serializer to use; typically when none ofSerializerFactory
instances are able to construct a serializer.Typically, returned serializer will throw an exception, although alternatively
ToStringSerializer
could be returned as well.- Parameters:
unknownType
- Type for which no serializer is found
-
isUnknownTypeSerializer
Helper method called to see if given serializer is considered to be something returned bygetUnknownTypeSerializer(java.lang.Class<?>)
, that is, something for which no regular serializer was found or constructed.- Since:
- 2.5
-
serializerInstance
public abstract JsonSerializer<Object> serializerInstance(Annotated annotated, Object serDef) throws JsonMappingException Method that can be called to construct and configure serializer instance, either given aClass
to instantiate (with default constructor), or an uninitialized serializer instance. Either way, serialize will be properly resolved (viaResolvableSerializer
) and/or contextualized (viaContextualSerializer
) as necessary.- Parameters:
annotated
- Annotated entity that contained definitionserDef
- Serializer definition: either an instance or class- Throws:
JsonMappingException
-
includeFilterInstance
public abstract Object includeFilterInstance(BeanPropertyDefinition forProperty, Class<?> filterClass) throws JsonMappingException Method that can be called to construct and configureJsonInclude
filter instance, given aClass
to instantiate (with default constructor, by default).- Parameters:
forProperty
- (optional) If filter is created for a property, that property; `null` if filter created via defaulting, global or per-type.- Throws:
JsonMappingException
- Since:
- 2.9
-
includeFilterSuppressNulls
Follow-up method that may be called after callingincludeFilterInstance(edu.internet2.middleware.grouperClientExt.com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition, java.lang.Class<?>)
, to check handling of `null` values by the filter.- Throws:
JsonMappingException
- Since:
- 2.9
-
handlePrimaryContextualization
public JsonSerializer<?> handlePrimaryContextualization(JsonSerializer<?> ser, BeanProperty property) throws JsonMappingException Method called for primary property serializers (ones directly created to serialize values of a POJO property), to handle details of resolvingContextualSerializer
with given property context.- Parameters:
property
- Property for which the given primary serializer is used; never null.- Throws:
JsonMappingException
- Since:
- 2.3
-
handleSecondaryContextualization
public JsonSerializer<?> handleSecondaryContextualization(JsonSerializer<?> ser, BeanProperty property) throws JsonMappingException Method called for secondary property serializers (ones NOT directly created to serialize values of a POJO property but instead created as a dependant serializer -- such as value serializers for structured types, or serializers for root values) to handle details of resolvingContextualDeserializer
with given property context. Given that these serializers are not directly related to given property (or, in case of root value property, to any property), annotations accessible may or may not be relevant.- Parameters:
property
- Property for which serializer is used, if any; null when deserializing root values- Throws:
JsonMappingException
- Since:
- 2.3
-
defaultSerializeValue
Convenience method that will serialize given value (which can be null) using standard serializer locating functionality. It can be called for all values including field and Map values, but usually field values are best handled callingdefaultSerializeField(java.lang.String, java.lang.Object, edu.internet2.middleware.grouperClientExt.com.fasterxml.jackson.core.JsonGenerator)
instead.- Throws:
IOException
-
defaultSerializeField
public final void defaultSerializeField(String fieldName, Object value, JsonGenerator gen) throws IOException Convenience method that will serialize given field with specified value. Value may be null. Serializer is done using the usual null) using standard serializer locating functionality.- Throws:
IOException
-
defaultSerializeDateValue
Method that will handle serialization of Date(-like) values, usingSerializationConfig
settings to determine expected serialization behavior. Note: date here means "full" date, that is, date AND time, as per Java convention (and not date-only values like in SQL)- Throws:
IOException
-
defaultSerializeDateValue
Method that will handle serialization of Date(-like) values, usingSerializationConfig
settings to determine expected serialization behavior. Note: date here means "full" date, that is, date AND time, as per Java convention (and not date-only values like in SQL)- Throws:
IOException
-
defaultSerializeDateKey
Method that will handle serialization of Dates used asMap
keys, based onSerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS
value (and if using textual representation, configured date format)- Throws:
IOException
-
defaultSerializeDateKey
Method that will handle serialization of Dates used asMap
keys, based onSerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS
value (and if using textual representation, configured date format)- Throws:
IOException
-
defaultSerializeNull
- Throws:
IOException
-
reportMappingProblem
Helper method called to indicate problem; default behavior is to construct and throw aJsonMappingException
, but in future may collect more than one and only throw after certain number, or at the end of serialization.- Throws:
JsonMappingException
- Since:
- 2.8
-
reportBadTypeDefinition
public <T> T reportBadTypeDefinition(BeanDescription bean, String msg, Object... msgArgs) throws JsonMappingException Helper method called to indicate problem in POJO (serialization) definitions or settings regarding specific Java type, unrelated to actual JSON content to map. Default behavior is to construct and throw aJsonMappingException
.- Throws:
JsonMappingException
- Since:
- 2.9
-
reportBadPropertyDefinition
public <T> T reportBadPropertyDefinition(BeanDescription bean, BeanPropertyDefinition prop, String message, Object... msgArgs) throws JsonMappingException Helper method called to indicate problem in POJO (serialization) definitions or settings regarding specific property (of a type), unrelated to actual JSON content to map. Default behavior is to construct and throw aJsonMappingException
.- Throws:
JsonMappingException
- Since:
- 2.9
-
reportBadDefinition
Description copied from class:DatabindContext
Helper method called to indicate a generic problem that stems from type definition(s), not input data, or input/output state; typically this means throwing aInvalidDefinitionException
.- Specified by:
reportBadDefinition
in classDatabindContext
- Throws:
JsonMappingException
-
reportBadDefinition
public <T> T reportBadDefinition(JavaType type, String msg, Throwable cause) throws JsonMappingException - Throws:
JsonMappingException
- Since:
- 2.9
-
reportBadDefinition
public <T> T reportBadDefinition(Class<?> raw, String msg, Throwable cause) throws JsonMappingException - Throws:
JsonMappingException
- Since:
- 2.9
-
reportMappingProblem
public void reportMappingProblem(Throwable t, String message, Object... msgArgs) throws JsonMappingException Helper method called to indicate problem; default behavior is to construct and throw aJsonMappingException
, but in future may collect more than one and only throw after certain number, or at the end of serialization.- Throws:
JsonMappingException
- Since:
- 2.8
-
invalidTypeIdException
public JsonMappingException invalidTypeIdException(JavaType baseType, String typeId, String extraDesc) Description copied from class:DatabindContext
Helper method for constructing exception to indicate that given type id could not be resolved to a valid subtype of specified base type. Most commonly called during polymorphic deserialization.Note that most of the time this method should NOT be called directly: instead, method
handleUnknownTypeId()
should be called which will call this method if necessary.- Specified by:
invalidTypeIdException
in classDatabindContext
-
mappingException
Deprecated.Since 2.9Factory method for constructing aJsonMappingException
; usually only indirectly used by callingreportMappingProblem(String, Object...)
.- Since:
- 2.6
-
mappingException
@Deprecated protected JsonMappingException mappingException(Throwable t, String message, Object... msgArgs) Deprecated.Since 2.9Factory method for constructing aJsonMappingException
; usually only indirectly used by callingreportMappingProblem(Throwable, String, Object...)
- Since:
- 2.8
-
_reportIncompatibleRootType
- Throws:
IOException
-
_findExplicitUntypedSerializer
protected JsonSerializer<Object> _findExplicitUntypedSerializer(Class<?> runtimeType) throws JsonMappingException Method that will try to find a serializer, either from cache or by constructing one; but will not return an "unknown" serializer if this cannot be done but rather returns null.- Returns:
- Serializer if one can be found, null if not.
- Throws:
JsonMappingException
-
_createAndCacheUntypedSerializer
protected JsonSerializer<Object> _createAndCacheUntypedSerializer(Class<?> rawType) throws JsonMappingException Method that will try to construct a value serializer; and if one is successfully created, cache it for reuse.- Throws:
JsonMappingException
-
_createAndCacheUntypedSerializer
protected JsonSerializer<Object> _createAndCacheUntypedSerializer(JavaType type) throws JsonMappingException - Throws:
JsonMappingException
-
_createUntypedSerializer
protected JsonSerializer<Object> _createUntypedSerializer(JavaType type) throws JsonMappingException - Throws:
JsonMappingException
- Since:
- 2.1
-
_handleContextualResolvable
protected JsonSerializer<Object> _handleContextualResolvable(JsonSerializer<?> ser, BeanProperty property) throws JsonMappingException Helper method called to resolve and contextualize given serializer, if and as necessary.- Throws:
JsonMappingException
-
_handleResolvable
protected JsonSerializer<Object> _handleResolvable(JsonSerializer<?> ser) throws JsonMappingException - Throws:
JsonMappingException
-
_dateFormat
-