- All Implemented Interfaces:
JsonFormatVisitable
ValueSerializers
that mostly delegate functionality to another serializer implementation
(possibly forming a chaining of serializers delegating functionality
in some cases).- Since:
- 3.1
-
Nested Class Summary
Nested classes/interfaces inherited from class tools.jackson.databind.ValueSerializer
ValueSerializer.None -
Field Summary
FieldsFields inherited from class tools.jackson.databind.ser.std.StdSerializer
_handledType -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final ValueSerializer<Object>_newIfChanged(ValueSerializer<?> newDelegatee) voidacceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType type) Default implementation specifies no format.createContextual(SerializationContext ctxt, BeanProperty property) Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property (or, for root values, in which case `null` is passed).Accessor that can be used to determine if this serializer uses another serializer for actual serialization, by delegating calls.Class<?>Method for accessing type of Objects this serializer can handle.booleanisEmpty(SerializationContext ctxt, Object value) Method called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values).booleanAccessor for checking whether this serializer is an "unwrapping" serializer; this is necessary to know since it may also require caller to suppress writing of the leading property name.protected abstract ValueSerializer<Object>newDelegatingInstance(ValueSerializer<?> newDelegatee) Accessor for iterating over logical properties that the type handled by this serializer has, from serialization perspective.replaceDelegatee(ValueSerializer<?> delegatee) Method that can be called to try to replace serializer this serializer delegates calls to.voidresolve(SerializationContext ctxt) Method called afterSerializationContexthas registered the serializer, but before it has returned it to the caller.voidserialize(Object value, tools.jackson.core.JsonGenerator gen, SerializationContext ctxt) Method that can be called to ask implementation to serialize values of type this serializer handles.voidserializeWithType(Object value, tools.jackson.core.JsonGenerator gen, SerializationContext ctxt, TypeSerializer typeSer) Method that can be called to ask implementation to serialize values of type this serializer handles, using specified type serializer for embedding necessary type information.unwrappingSerializer(NameTransformer unwrapper) Method that will return serializer instance that produces "unwrapped" serialization, if applicable for type being serialized (which is the case for some serializers that produce JSON Objects as output).booleanMethod that can be called to see whether this serializer instance will use Object Id to handle cyclic references.withFilterId(Object filterId) Mutant factory method that is called if contextual configuration indicates that a specific filter (as specified byfilterId) is to be used for serialization.withFormatOverrides(SerializationConfig config, JsonFormat.Value formatOverrides) Mutant factory called if there is need to create a serializer with specified format overrides (typically from property on which this serializer would be used, based on type declaration).withIgnoredProperties(Set<String> ignoredProperties) Mutant factory method called to create a new instance after excluding specified set of properties by name, if there is any.Methods inherited from class tools.jackson.databind.ser.std.StdSerializer
_neitherNull, _nonEmpty, _wrapIOFailure, acceptJsonFormatVisitorForBinary, createSchemaNode, createSchemaNode, findAnnotatedContentSerializer, findContextualConvertingSerializer, findFormatFeature, findFormatOverrides, findIncludeOverrides, findPropertyFilter, isDefaultSerializer, visitArrayFormat, visitArrayFormat, visitFloatFormat, visitIntFormat, visitIntFormat, visitStringFormat, visitStringFormat, wrapAndThrow, wrapAndThrow
-
Field Details
-
_delegatee
-
-
Constructor Details
-
DelegatingSerializer
-
-
Method Details
-
newDelegatingInstance
-
_newIfChanged
-
replaceDelegatee
Description copied from class:ValueSerializerMethod that can be called to try to replace serializer this serializer delegates calls to. If not supported (either this serializer does not delegate anything; or it does not want any changes), should either throwUnsupportedOperationException(if operation does not make sense or is not allowed); or return this serializer as is.- Overrides:
replaceDelegateein classValueSerializer<Object>
-
unwrappingSerializer
Description copied from class:ValueSerializerMethod that will return serializer instance that produces "unwrapped" serialization, if applicable for type being serialized (which is the case for some serializers that produce JSON Objects as output). If no unwrapped serializer can be constructed, will simply return serializer as-is.Default implementation just returns serializer as-is, indicating that no unwrapped variant exists
- Overrides:
unwrappingSerializerin classValueSerializer<Object>- Parameters:
unwrapper- Name transformation to use to convert between names of unwrapper properties
-
withFilterId
Description copied from class:ValueSerializerMutant factory method that is called if contextual configuration indicates that a specific filter (as specified byfilterId) is to be used for serialization.Default implementation simply returns
this; sub-classes that do support filtering will need to create and return new instance if filter changes.- Overrides:
withFilterIdin classValueSerializer<Object>
-
withFormatOverrides
public ValueSerializer<?> withFormatOverrides(SerializationConfig config, JsonFormat.Value formatOverrides) Description copied from class:ValueSerializerMutant factory called if there is need to create a serializer with specified format overrides (typically from property on which this serializer would be used, based on type declaration). Method is called beforeValueSerializer.createContextual(tools.jackson.databind.SerializationContext, tools.jackson.databind.BeanProperty)but right after serializer is either constructed or fetched from cache.Method can do one of three things:
- Return
thisinstance as is: this means that none of overrides has any effect - Return an alternate
ValueSerializer, suitable for use with specified format - Return
nullto indicate that this serializer instance is not suitable for handling format variation, but does not know how to construct new serializer: caller will typically then callSerializerFactorywith overrides to construct new serializer
JsonFormat.Shape.STRINGindicates String representation and code can just construct simple "string-like serializer", or variant of itself (similar to howValueSerializer.createContextual(tools.jackson.databind.SerializationContext, tools.jackson.databind.BeanProperty)is often implemented). And third case (returningnull) is applicable for cases like format definesJsonFormat.Shape.POJO, requesting "introspect serializer for POJO regardless of type":SerializerFactoryis needed for full re-introspection, typically.- Overrides:
withFormatOverridesin classValueSerializer<Object>formatOverrides- (not null) Override settings, NOT including original format settings (which serializer needs to explicitly retain if needed)
- Return
-
withIgnoredProperties
Description copied from class:ValueSerializerMutant factory method called to create a new instance after excluding specified set of properties by name, if there is any.- Overrides:
withIgnoredPropertiesin classValueSerializer<Object>- Parameters:
ignoredProperties- Set of property names to ignore for serialization;- Returns:
- Serializer instance that without specified set of properties to ignore (if any)
-
resolve
Description copied from class:ValueSerializerMethod called afterSerializationContexthas registered the serializer, but before it has returned it to the caller. Called object can then resolve its dependencies to other types, including self-references (direct or indirect).Note that this method does NOT return serializer, since resolution is not allowed to change actual serializer to use.
- Overrides:
resolvein classValueSerializer<Object>- Parameters:
ctxt- Currently active serialization context.
-
createContextual
Description copied from class:ValueSerializerMethod called to see if a different (or differently configured) serializer is needed to serialize values of specified property (or, for root values, in which case `null` is passed). Note that instance that this method is called on is typically shared one and as a result method should NOT modify this instance but rather construct and return a new instance. This instance should only be returned as-is, in case it is already suitable for use.Note that method is only called once per POJO property, and for the first usage as root value serializer; it is not called for every serialization, as doing that would have significant performance impact; most serializers cache contextual instances for future use.
- Overrides:
createContextualin classValueSerializer<Object>- Parameters:
ctxt- Context to use for accessing config, other serializersproperty- Property (defined by one or more accessors - field or method - used for accessing logical property value) for which serializer is used to be used; or, `null` for root value (or in cases where caller does not have this information, which is handled as root value case).- Returns:
- Serializer to use for serializing values of specified property; may be this instance or a new instance.
-
isEmpty
Description copied from class:ValueSerializerMethod called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values).Default implementation will consider only null values to be empty.
- Overrides:
isEmptyin classValueSerializer<Object>
-
serialize
public void serialize(Object value, tools.jackson.core.JsonGenerator gen, SerializationContext ctxt) Description copied from class:ValueSerializerMethod that can be called to ask implementation to serialize values of type this serializer handles.- Specified by:
serializein classStdSerializer<Object>- Parameters:
value- Value to serialize; can not be null.gen- Generator used to output resulting Json contentctxt- Context that can be used to get serializers for serializing Objects value contains, if any.
-
serializeWithType
public void serializeWithType(Object value, tools.jackson.core.JsonGenerator gen, SerializationContext ctxt, TypeSerializer typeSer) Description copied from class:ValueSerializerMethod that can be called to ask implementation to serialize values of type this serializer handles, using specified type serializer for embedding necessary type information.Default implementation will throw
UnsupportedOperationExceptionto indicate that proper type handling needs to be implemented.For simple datatypes written as a single scalar value (JSON String, Number, Boolean), implementation would look like:
// note: method to call depends on whether this type is serialized as JSON scalar, object or Array! typeSer.writeTypePrefixForScalar(value, gen); serialize(value, gen, ctxt); typeSer.writeTypeSuffixForScalar(value, gen);
and implementations for type serialized as JSON Arrays or Objects would differ slightly, asSTART-ARRAY/END-ARRAYandSTART-OBJECT/END-OBJECTpairs need to be properly handled with respect to serializing of contents.- Overrides:
serializeWithTypein classValueSerializer<Object>- Parameters:
value- Value to serialize; can not be null.gen- Generator used to output resulting Json contentctxt- Context that can be used to get serializers for serializing Objects value contains, if any.typeSer- Type serializer to use for including type information
-
handledType
Description copied from class:ValueSerializerMethod for accessing type of Objects this serializer can handle. Note that this information is not guaranteed to be exact -- it may be a more generic (super-type) -- but it should not be incorrect (return a non-related type).NOTE: starting with 3.0, left
abstract.- Overrides:
handledTypein classStdSerializer<Object>
-
usesObjectId
public boolean usesObjectId()Description copied from class:ValueSerializerMethod that can be called to see whether this serializer instance will use Object Id to handle cyclic references.- Overrides:
usesObjectIdin classValueSerializer<Object>
-
isUnwrappingSerializer
public boolean isUnwrappingSerializer()Description copied from class:ValueSerializerAccessor for checking whether this serializer is an "unwrapping" serializer; this is necessary to know since it may also require caller to suppress writing of the leading property name.- Overrides:
isUnwrappingSerializerin classValueSerializer<Object>
-
getDelegatee
Description copied from class:ValueSerializerAccessor that can be used to determine if this serializer uses another serializer for actual serialization, by delegating calls. If so, will return immediate delegate (which itself may delegate to further serializers); otherwise will return null.- Overrides:
getDelegateein classValueSerializer<Object>- Returns:
- Serializer this serializer delegates calls to, if null; null otherwise.
-
properties
Description copied from class:ValueSerializerAccessor for iterating over logical properties that the type handled by this serializer has, from serialization perspective. Actual type of properties, if any, will beBeanPropertyWriter. Of standard Jackson serializers, onlyBeanSerializerexposes properties.- Overrides:
propertiesin classValueSerializer<Object>
-
acceptJsonFormatVisitor
Description copied from class:StdSerializerDefault implementation specifies no format. This behavior is usually overriden by custom serializers.- Specified by:
acceptJsonFormatVisitorin interfaceJsonFormatVisitable- Overrides:
acceptJsonFormatVisitorin classStdSerializer<Object>type- Type of element (entity like property) being visited
-