java.lang.Object
tools.jackson.databind.ValueSerializer<T>
tools.jackson.databind.ser.std.StdSerializer<T>
- All Implemented Interfaces:
JsonFormatVisitable
- Direct Known Subclasses:
BeanSerializerBase
,ByteArraySerializer
,DOMSerializer
,DoubleStreamSerializer
,DurationSerializer
,FailingSerializer
,InstantSerializerBase
,IntStreamSerializer
,JacksonSerializableSerializer
,Jdk8StreamSerializer
,JDKArraySerializers.BinaryDoubleArraySerializer
,JDKArraySerializers.BinaryFloatArraySerializer
,JDKArraySerializers.CharArraySerializer
,JDKKeySerializers.Default
,JDKKeySerializers.Dynamic
,JDKKeySerializers.EnumKeySerializer
,JDKKeySerializers.StringKeySerializer
,JDKStringLikeSerializer
,LocalDateSerializer
,LocalDateTimeSerializer
,LocalTimeSerializer
,LongStreamSerializer
,MapEntryAsPOJOSerializer
,MonthDaySerializer
,MonthSerializer
,NullSerializer
,OffsetTimeSerializer
,QNameSerializer
,RawSerializer
,StaticListSerializerBase
,StdContainerSerializer
,StdDelegatingSerializer
,StdDynamicSerializer
,StdScalarSerializer
,ToEmptyObjectSerializer
,TokenBufferSerializer
,ToStringSerializerBase
,UnsupportedTypeSerializer
,XMLGregorianCalendarSerializer
,YearMonthSerializer
,YearSerializer
Base class used by all standard serializers, and can also
be used for custom serializers (in fact, this is the recommended
base class to use).
-
Nested Class Summary
Nested classes/interfaces inherited from class tools.jackson.databind.ValueSerializer
ValueSerializer.None
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Class<?>
Nominal type supported, usually declared type of property for which serializer is used. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
StdSerializer
(Class<?> t) protected
StdSerializer
(Class<?> t, boolean dummy) Deprecated.protected
StdSerializer
(JavaType type) protected
StdSerializer
(StdSerializer<?> src) -
Method Summary
Modifier and TypeMethodDescriptionprotected static final boolean
_neitherNull
(Object a, Object b) protected static final boolean
_nonEmpty
(Collection<?> c) protected JacksonException
void
acceptJsonFormatVisitor
(JsonFormatVisitorWrapper visitor, JavaType typeHint) Default implementation specifies no format.protected void
acceptJsonFormatVisitorForBinary
(JsonFormatVisitorWrapper visitor, JavaType typeHint) Helper method for handling Binary values: typically serialized as Base64-encoded data (in textual formats) or native binary (binary formats).protected ObjectNode
createSchemaNode
(String type) protected ObjectNode
createSchemaNode
(String type, boolean isOptional) protected ValueSerializer<?>
findAnnotatedContentSerializer
(SerializationContext serializers, BeanProperty property) Convenience method for finding out possibly configured content value serializer.protected ValueSerializer<?>
findContextualConvertingSerializer
(SerializationContext provider, BeanProperty prop, ValueSerializer<?> existingSerializer) Helper method that can be used to see if specified property has annotation indicating that a converter is to be used for contained values (contents of structured types; array/List/Map values)protected Boolean
findFormatFeature
(SerializationContext provider, BeanProperty prop, Class<?> typeForDefaults, JsonFormat.Feature feat) Convenience method that usesfindFormatOverrides(tools.jackson.databind.SerializationContext, tools.jackson.databind.BeanProperty, java.lang.Class<?>)
to find possible defaults and/of overrides, and then callsJsonFormat.Value.getFeature(...)
to find whether that feature has been specifically marked as enabled or disabled.protected JsonFormat.Value
findFormatOverrides
(SerializationContext provider, BeanProperty prop, Class<?> typeForDefaults) Helper method that may be used to find if this deserializer has specificJsonFormat
settings, either via property, or through type-specific defaulting.protected JsonInclude.Value
findIncludeOverrides
(SerializationContext provider, BeanProperty prop, Class<?> typeForDefaults) protected PropertyFilter
findPropertyFilter
(SerializationContext provider, Object filterId, Object valueToFilter) Helper method used to locate filter that is needed, based on filter id this serializer was constructed with.Class<?>
Method for accessing type of Objects this serializer can handle.protected boolean
isDefaultSerializer
(ValueSerializer<?> serializer) Method that can be called to determine if given serializer is the default serializer Jackson uses; as opposed to a custom serializer installed by a module or calling application.abstract void
serialize
(T value, JsonGenerator gen, SerializationContext provider) Method that can be called to ask implementation to serialize values of type this serializer handles.protected void
visitArrayFormat
(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonFormatTypes itemType) protected void
visitArrayFormat
(JsonFormatVisitorWrapper visitor, JavaType typeHint, ValueSerializer<?> itemSerializer, JavaType itemType) protected void
visitFloatFormat
(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonParser.NumberType numberType) Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is a floating-point JSON number.protected void
visitIntFormat
(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonParser.NumberType numberType) Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON Integer number.protected void
visitIntFormat
(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonParser.NumberType numberType, JsonValueFormat format) Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON Integer number, but that there is also a further format restriction involved.protected void
visitStringFormat
(JsonFormatVisitorWrapper visitor, JavaType typeHint) Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON String.protected void
visitStringFormat
(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonValueFormat format) Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON String, but that there is a more refined logical typevoid
wrapAndThrow
(SerializationContext ctxt, Throwable t, Object bean, int index) void
wrapAndThrow
(SerializationContext ctxt, Throwable t, Object bean, String fieldName) Method that will modify caught exception (passed in as argument) as necessary to include reference information, and to ensure it is a subtype ofJacksonException
, or an unchecked exception.Methods inherited from class tools.jackson.databind.ValueSerializer
createContextual, getDelegatee, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, resolve, serializeWithType, unwrappingSerializer, usesObjectId, withFilterId, withFormatOverrides, withIgnoredProperties
-
Field Details
-
_handledType
Nominal type supported, usually declared type of property for which serializer is used.
-
-
Constructor Details
-
StdSerializer
-
StdSerializer
-
StdSerializer
Deprecated.Alternate constructor that is (alas!) needed to work around kinks of generic type handling -
StdSerializer
-
-
Method Details
-
handledType
Description copied from class:ValueSerializer
Method 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:
handledType
in classValueSerializer<T>
-
serialize
public abstract void serialize(T value, JsonGenerator gen, SerializationContext provider) throws JacksonException Description copied from class:ValueSerializer
Method that can be called to ask implementation to serialize values of type this serializer handles.- Specified by:
serialize
in classValueSerializer<T>
- Parameters:
value
- Value to serialize; can not be null.gen
- Generator used to output resulting Json contentprovider
- Context that can be used to get serializers for serializing Objects value contains, if any.- Throws:
JacksonException
-
acceptJsonFormatVisitor
Default implementation specifies no format. This behavior is usually overriden by custom serializers.- Specified by:
acceptJsonFormatVisitor
in interfaceJsonFormatVisitable
- Overrides:
acceptJsonFormatVisitor
in classValueSerializer<T>
typeHint
- Type of element (entity like property) being visited
-
acceptJsonFormatVisitorForBinary
protected void acceptJsonFormatVisitorForBinary(JsonFormatVisitorWrapper visitor, JavaType typeHint) Helper method for handling Binary values: typically serialized as Base64-encoded data (in textual formats) or native binary (binary formats). -
createSchemaNode
-
createSchemaNode
-
visitStringFormat
Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON String. -
visitStringFormat
protected void visitStringFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonValueFormat format) Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON String, but that there is a more refined logical type -
visitIntFormat
protected void visitIntFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonParser.NumberType numberType) Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON Integer number. -
visitIntFormat
protected void visitIntFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonParser.NumberType numberType, JsonValueFormat format) Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON Integer number, but that there is also a further format restriction involved. -
visitFloatFormat
protected void visitFloatFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonParser.NumberType numberType) Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is a floating-point JSON number. -
visitArrayFormat
protected void visitArrayFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, ValueSerializer<?> itemSerializer, JavaType itemType) -
visitArrayFormat
protected void visitArrayFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, JsonFormatTypes itemType) -
wrapAndThrow
public void wrapAndThrow(SerializationContext ctxt, Throwable t, Object bean, String fieldName) throws JacksonException Method that will modify caught exception (passed in as argument) as necessary to include reference information, and to ensure it is a subtype ofJacksonException
, or an unchecked exception.Rules for wrapping and unwrapping are bit complicated; essentially:
- Errors are to be passed as is (if uncovered via unwrapping)
- Wrapped
IOException
s are unpeeled
- Throws:
JacksonException
-
wrapAndThrow
public void wrapAndThrow(SerializationContext ctxt, Throwable t, Object bean, int index) throws JacksonException - Throws:
JacksonException
-
findContextualConvertingSerializer
protected ValueSerializer<?> findContextualConvertingSerializer(SerializationContext provider, BeanProperty prop, ValueSerializer<?> existingSerializer) Helper method that can be used to see if specified property has annotation indicating that a converter is to be used for contained values (contents of structured types; array/List/Map values)- Parameters:
existingSerializer
- (optional) configured content serializer if one already exists.
-
findPropertyFilter
protected PropertyFilter findPropertyFilter(SerializationContext provider, Object filterId, Object valueToFilter) Helper method used to locate filter that is needed, based on filter id this serializer was constructed with. -
findFormatOverrides
protected JsonFormat.Value findFormatOverrides(SerializationContext provider, BeanProperty prop, Class<?> typeForDefaults) Helper method that may be used to find if this deserializer has specificJsonFormat
settings, either via property, or through type-specific defaulting.- Parameters:
typeForDefaults
- Type (erased) used for finding default format settings, if any
-
findFormatFeature
protected Boolean findFormatFeature(SerializationContext provider, BeanProperty prop, Class<?> typeForDefaults, JsonFormat.Feature feat) Convenience method that usesfindFormatOverrides(tools.jackson.databind.SerializationContext, tools.jackson.databind.BeanProperty, java.lang.Class<?>)
to find possible defaults and/of overrides, and then callsJsonFormat.Value.getFeature(...)
to find whether that feature has been specifically marked as enabled or disabled.- Parameters:
typeForDefaults
- Type (erased) used for finding default format settings, if any
-
findIncludeOverrides
protected JsonInclude.Value findIncludeOverrides(SerializationContext provider, BeanProperty prop, Class<?> typeForDefaults) -
findAnnotatedContentSerializer
protected ValueSerializer<?> findAnnotatedContentSerializer(SerializationContext serializers, BeanProperty property) Convenience method for finding out possibly configured content value serializer. -
isDefaultSerializer
Method that can be called to determine if given serializer is the default serializer Jackson uses; as opposed to a custom serializer installed by a module or calling application. Determination is done usingJacksonStdImpl
annotation on serializer class. -
_neitherNull
-
_nonEmpty
-
_wrapIOFailure
-