Class StdSerializer<T>
- java.lang.Object
-
- com.fasterxml.jackson.databind.JsonSerializer<T>
-
- com.fasterxml.jackson.databind.ser.std.StdSerializer<T>
-
- All Implemented Interfaces:
JsonFormatVisitable
,SchemaAware
,java.io.Serializable
- Direct Known Subclasses:
BeanSerializerBase
,ByteArraySerializer
,ComponentDataModelSerializer
,ContainerSerializer
,CoreXMLSerializers.XMLGregorianCalendarSerializer
,DOMSerializer
,DurationSerializer
,FailingSerializer
,InstantSerializerBase
,JsonValueSerializer
,LocalDateSerializer
,LocalDateTimeSerializer
,LocalTimeSerializer
,MonthDaySerializer
,NullSerializer
,OffsetTimeSerializer
,RawSerializer
,ReferenceTypeSerializer
,SerializableSerializer
,StaticListSerializerBase
,StdArraySerializers.CharArraySerializer
,StdDelegatingSerializer
,StdKeySerializer
,StdKeySerializers.Default
,StdKeySerializers.Dynamic
,StdKeySerializers.EnumKeySerializer
,StdKeySerializers.StringKeySerializer
,StdScalarSerializer
,ToEmptyObjectSerializer
,TokenBufferSerializer
,ToStringSerializerBase
,UnsupportedTypeSerializer
,YearMonthSerializer
,YearSerializer
public abstract class StdSerializer<T> extends JsonSerializer<T> implements JsonFormatVisitable, SchemaAware, java.io.Serializable
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). Provides convenience methods for implementingSchemaAware
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer
JsonSerializer.None
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
Default implementation specifies no format.JsonNode
getSchema(SerializerProvider provider, java.lang.reflect.Type typeHint)
Default implementation simply claims type is "string"; usually overriden by custom serializers.JsonNode
getSchema(SerializerProvider provider, java.lang.reflect.Type typeHint, boolean isOptional)
Default implementation simply claims type is "string"; usually overriden by custom serializers.java.lang.Class<T>
handledType()
Method for accessing type of Objects this serializer can handle.abstract void
serialize(T value, JsonGenerator gen, SerializerProvider provider)
Method that can be called to ask implementation to serialize values of type this serializer handles.void
wrapAndThrow(SerializerProvider provider, java.lang.Throwable t, java.lang.Object bean, int index)
void
wrapAndThrow(SerializerProvider provider, java.lang.Throwable t, java.lang.Object bean, java.lang.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 ofIOException
, or an unchecked exception.-
Methods inherited from class com.fasterxml.jackson.databind.JsonSerializer
getDelegatee, isEmpty, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, serializeWithType, unwrappingSerializer, usesObjectId, withFilterId
-
-
-
-
Method Detail
-
handledType
public java.lang.Class<T> handledType()
Description copied from class:JsonSerializer
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).Default implementation will return null, which essentially means same as returning
Object.class
would; that is, that nothing is known about handled type.- Overrides:
handledType
in classJsonSerializer<T>
-
serialize
public abstract void serialize(T value, JsonGenerator gen, SerializerProvider provider) throws java.io.IOException
Description copied from class:JsonSerializer
Method that can be called to ask implementation to serialize values of type this serializer handles.- Specified by:
serialize
in classJsonSerializer<T>
- Parameters:
value
- Value to serialize; can not be null.gen
- Generator used to output resulting Json contentprovider
- Provider that can be used to get serializers for serializing Objects value contains, if any.- Throws:
java.io.IOException
-
acceptJsonFormatVisitor
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
Default implementation specifies no format. This behavior is usually overriden by custom serializers.- Specified by:
acceptJsonFormatVisitor
in interfaceJsonFormatVisitable
- Overrides:
acceptJsonFormatVisitor
in classJsonSerializer<T>
typeHint
- Type of element (entity like property) being visited- Throws:
JsonMappingException
-
getSchema
public JsonNode getSchema(SerializerProvider provider, java.lang.reflect.Type typeHint) throws JsonMappingException
Default implementation simply claims type is "string"; usually overriden by custom serializers.- Specified by:
getSchema
in interfaceSchemaAware
- Parameters:
provider
- The serializer provider.typeHint
- A hint about the type.- Returns:
- Json-schema for this serializer.
- Throws:
JsonMappingException
-
getSchema
public JsonNode getSchema(SerializerProvider provider, java.lang.reflect.Type typeHint, boolean isOptional) throws JsonMappingException
Default implementation simply claims type is "string"; usually overriden by custom serializers.- Specified by:
getSchema
in interfaceSchemaAware
- Parameters:
provider
- The serializer provider.typeHint
- A hint about the type.isOptional
- Is the type optional- Returns:
- Json-schema for this serializer.
- Throws:
JsonMappingException
-
wrapAndThrow
public void wrapAndThrow(SerializerProvider provider, java.lang.Throwable t, java.lang.Object bean, java.lang.String fieldName) throws java.io.IOException
Method that will modify caught exception (passed in as argument) as necessary to include reference information, and to ensure it is a subtype ofIOException
, or an unchecked exception.Rules for wrapping and unwrapping are bit complicated; essentially:
- Errors are to be passed as is (if uncovered via unwrapping)
- "Plain" IOExceptions (ones that are not of type
JsonMappingException
are to be passed as is
- Throws:
java.io.IOException
-
wrapAndThrow
public void wrapAndThrow(SerializerProvider provider, java.lang.Throwable t, java.lang.Object bean, int index) throws java.io.IOException
- Throws:
java.io.IOException
-
-