com.fasterxml.jackson.databind.ser.std

## 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

Direct Known Subclasses:
  BeanSerializerBase, ContainerSerializer, CoreXMLSerializers.XMLGregorianCalendarSerializer, DOMSerializer, FailingSerializer, JsonValueSerializer, NullSerializer, RawSerializer, SerializableSerializer, StaticListSerializerBase, StdArraySerializers.ByteArraySerializer, StdArraySerializers.CharArraySerializer, StdDelegatingSerializer, StdJdkSerializers.AtomicReferenceSerializer, StdKeySerializer, StdKeySerializers.CalendarKeySerializer, StdKeySerializers.DateKeySerializer, StdKeySerializers.StringKeySerializer, StdScalarSerializer, TokenBufferSerializer, ToStringSerializer, UnknownSerializer

    public abstract class StdSerializer<T>
    extends JsonSerializer<T>
    implements JsonFormatVisitable, SchemaAware

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 implementing `SchemaAware`

### Nested Class Summary

### Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer

`JsonSerializer.None`

### Field Summary

Fields
`protected Class<T>` `_handledType` Nominal type supported, usually declared type of property for which serializer is used.

### Constructor Summary

Constructors
`protected` `StdSerializer(Class<?> t, boolean dummy)` Alternate constructor that is (alas!) needed to work around kinks of generic type handling
`protected` `StdSerializer(Class<T> t)`
`protected` `StdSerializer(JavaType type)`

### Method Summary

Methods
`void` `acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)` Default implementation specifies no format.
`protected ObjectNode` `createObjectNode()`
`protected ObjectNode` `createSchemaNode(String type)`
`protected ObjectNode` `createSchemaNode(String type, boolean isOptional)`
`protected JsonSerializer<?>` `findConvertingContentSerializer(SerializerProvider provider, BeanProperty prop, JsonSerializer<?> 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)
`JsonNode` `getSchema(SerializerProvider provider, Type typeHint)` Default implementation simply claims type is "string"; usually overriden by custom serializers.
`JsonNode` `getSchema(SerializerProvider provider, Type typeHint, boolean isOptional)` Default implementation simply claims type is "string"; usually overriden by custom serializers.
`Class<T>` `handledType()` Method for accessing type of Objects this serializer can handle.
`protected boolean` `isDefaultSerializer(JsonSerializer<?> 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 jgen, SerializerProvider provider)` Method that can be called to ask implementation to serialize values of type this serializer handles.
`void` `wrapAndThrow(SerializerProvider provider, Throwable t, Object bean, int index)`
`void` `wrapAndThrow(SerializerProvider provider, 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 of `IOException`, or an unchecked exception.

### Methods inherited from class com.fasterxml.jackson.databind.JsonSerializer

`getDelegatee, isEmpty, isUnwrappingSerializer, replaceDelegatee, serializeWithType, unwrappingSerializer, usesObjectId`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### _handledType

    protected final Class<T> _handledType

Nominal type supported, usually declared type of property for which serializer is used.

### Constructor Detail

#### StdSerializer

    protected StdSerializer(Class<T> t)

#### StdSerializer

    protected StdSerializer(JavaType type)

#### StdSerializer

    protected StdSerializer(Class<?> t,
                 boolean dummy)

Alternate constructor that is (alas!) needed to work around kinks of generic type handling

### Method Detail

#### handledType

    public 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 class `JsonSerializer<T>`

#### serialize

    public abstract void serialize(T value,
                 JsonGenerator jgen,
                 SerializerProvider provider)
                            throws IOException,
                                   JsonGenerationException

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 class `JsonSerializer<T>`
Parameters:
  `value` - Value to serialize; can not be null.
  `jgen` - Generator used to output resulting Json content
  `provider` - Provider that can be used to get serializers for serializing Objects value contains, if any.
Throws:
  `IOException`
  `JsonGenerationException`

#### getSchema

    public JsonNode getSchema(SerializerProvider provider,
                     Type typeHint)
                       throws JsonMappingException

Default implementation simply claims type is "string"; usually overriden by custom serializers.

Specified by:
  `getSchema` in interface `SchemaAware`
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,
                     Type typeHint,
                     boolean isOptional)
                       throws JsonMappingException

Default implementation simply claims type is "string"; usually overriden by custom serializers.

Specified by:
  `getSchema` in interface `SchemaAware`
Parameters:
  `provider` - The serializer provider.
  `typeHint` - A hint about the type.
  `isOptional` - Is the type optional
Returns:
  Json-schema for this serializer.
Throws:
  `JsonMappingException`

#### createObjectNode

    protected ObjectNode createObjectNode()

#### createSchemaNode

    protected ObjectNode createSchemaNode(String type)

#### createSchemaNode

    protected ObjectNode createSchemaNode(String type,
                              boolean isOptional)

#### 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 interface `JsonFormatVisitable`
Overrides:
  `acceptJsonFormatVisitor` in class `JsonSerializer<T>`
  `typeHint` - Type of element (entity like property) being visited
Throws:
  `JsonMappingException`

#### wrapAndThrow

    public void wrapAndThrow(SerializerProvider provider,
                    Throwable t,
                    Object bean,
                    String fieldName)
                      throws IOException

Method that will modify caught exception (passed in as argument) as necessary to include reference information, and to ensure it is a subtype of `IOException`, 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:
  `IOException`

#### wrapAndThrow

    public void wrapAndThrow(SerializerProvider provider,
                    Throwable t,
                    Object bean,
                    int index)
                      throws IOException

Throws:
  `IOException`

#### isDefaultSerializer

    protected boolean isDefaultSerializer(JsonSerializer<?> 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. Determination is done using `JacksonStdImpl` annotation on serializer class.

#### findConvertingContentSerializer

    protected JsonSerializer<?> findConvertingContentSerializer(SerializerProvider provider,
                                                    BeanProperty prop,
                                                    JsonSerializer<?> existingSerializer)
                                                         throws JsonMappingException

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.
Throws:
  `JsonMappingException`
Since:
  2.2