StdSerializer
Date: 2016-12-04

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, java.io.Serializable
  Direct Known Subclasses:
    BeanSerializerBase, ByteArraySerializer, ContainerSerializer, CoreXMLSerializers.XMLGregorianCalendarSerializer, DOMSerializer, FailingSerializer, JsonValueSerializer, NullSerializer, RawSerializer, ReferenceTypeSerializer, SerializableSerializer, StaticListSerializerBase, StdArraySerializers.CharArraySerializer, StdDelegatingSerializer, StdKeySerializer, StdKeySerializers.Default, StdKeySerializers.Dynamic, StdKeySerializers.EnumKeySerializer, StdKeySerializers.StringKeySerializer, StdScalarSerializer, TokenBufferSerializer, ToStringSerializer, UnknownSerializer

      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 implementing `SchemaAware`
  See Also:
    Serialized Form

- - ### Nested Class Summary

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

      `JsonSerializer.None`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.lang.Class<T>` | `_handledType` Nominal type supported, usually declared type of property for which serializer is used.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `StdSerializer(java.lang.Class<?> t, boolean dummy)` Alternate constructor that is (alas!) needed to work around kinks of generic type handling
    `protected` | `StdSerializer(java.lang.Class<T> t)`
    `protected` | `StdSerializer(JavaType type)`
    `protected` | `StdSerializer(StdSerializer<?> src)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)` Default implementation specifies no format.
    `protected ObjectNode` | `createObjectNode()`
    `protected ObjectNode` | `createSchemaNode(java.lang.String type)`
    `protected ObjectNode` | `createSchemaNode(java.lang.String type, boolean isOptional)`
    `protected JsonSerializer<?>` | `findAnnotatedContentSerializer(SerializerProvider serializers, BeanProperty property)` Convenience method for finding out possibly configured content value serializer.
    `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)
    `protected java.lang.Boolean` | `findFormatFeature(SerializerProvider provider, BeanProperty prop, java.lang.Class<?> typeForDefaults, com.fasterxml.jackson.annotation.JsonFormat.Feature feat)` Convenience method that uses `findFormatOverrides(com.fasterxml.jackson.databind.SerializerProvider, com.fasterxml.jackson.databind.BeanProperty, java.lang.Class<?>)` to find possible defaults and/of overrides, and then calls `JsonFormat.Value.getFeature(...)` to find whether that feature has been specifically marked as enabled or disabled.
    `protected com.fasterxml.jackson.annotation.JsonFormat.Value` | `findFormatOverrides(SerializerProvider provider, BeanProperty prop, java.lang.Class<?> typeForDefaults)` Helper method that may be used to find if this deserializer has specific `JsonFormat` settings, either via property, or through type-specific defaulting.
    `protected com.fasterxml.jackson.annotation.JsonInclude.Value` | `findIncludeOverrides(SerializerProvider provider, BeanProperty prop, java.lang.Class<?> typeForDefaults)`
    `protected PropertyFilter` | `findPropertyFilter(SerializerProvider provider, java.lang.Object filterId, java.lang.Object valueToFilter)` Helper method used to locate filter that is needed, based on filter id this serializer was constructed with.
    `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.
    `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, com.fasterxml.jackson.core.JsonGenerator gen, SerializerProvider 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, JsonSerializer<?> itemSerializer, JavaType itemType)`
    `protected void` | `visitFloatFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, com.fasterxml.jackson.core.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, com.fasterxml.jackson.core.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, com.fasterxml.jackson.core.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 type
    `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 of `IOException`, or an unchecked exception.

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

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

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

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

- - ### Field Detail

    - #### _handledType

          protected final java.lang.Class<T> _handledType

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

  - ### Constructor Detail

    - #### StdSerializer

          protected StdSerializer(java.lang.Class<T> t)

    - #### StdSerializer

          protected StdSerializer(JavaType type)

    - #### StdSerializer

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

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

    - #### StdSerializer

          protected StdSerializer(StdSerializer<?> src)

      Since:
        2.6

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

    - #### serialize

          public abstract void serialize(T value,
                       com.fasterxml.jackson.core.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 class `JsonSerializer<T>`
      Parameters:
        `value` - Value to serialize; can not be null.
        `gen` - Generator used to output resulting Json content
        `provider` - 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 interface `JsonFormatVisitable`
      Overrides:
        `acceptJsonFormatVisitor` in class `JsonSerializer<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 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,
                           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 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(java.lang.String type)

    - #### createSchemaNode

          protected ObjectNode createSchemaNode(java.lang.String type,
                                    boolean isOptional)

    - #### visitStringFormat

          protected void visitStringFormat(JsonFormatVisitorWrapper visitor,
                               JavaType typeHint)
                                    throws JsonMappingException

      Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON String.
      Throws:
        `JsonMappingException`
      Since:
        2.7

    - #### visitStringFormat

          protected void visitStringFormat(JsonFormatVisitorWrapper visitor,
                               JavaType typeHint,
                               JsonValueFormat format)
                                    throws JsonMappingException

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

    - #### visitIntFormat

          protected void visitIntFormat(JsonFormatVisitorWrapper visitor,
                            JavaType typeHint,
                            com.fasterxml.jackson.core.JsonParser.NumberType numberType)
                                 throws JsonMappingException

      Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is JSON Integer number.
      Throws:
        `JsonMappingException`
      Since:
        2.7

    - #### visitIntFormat

          protected void visitIntFormat(JsonFormatVisitorWrapper visitor,
                            JavaType typeHint,
                            com.fasterxml.jackson.core.JsonParser.NumberType numberType,
                            JsonValueFormat format)
                                 throws JsonMappingException

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

    - #### visitFloatFormat

          protected void visitFloatFormat(JsonFormatVisitorWrapper visitor,
                              JavaType typeHint,
                              com.fasterxml.jackson.core.JsonParser.NumberType numberType)
                                   throws JsonMappingException

      Helper method that calls necessary visit method(s) to indicate that the underlying JSON type is a floating-point JSON number.
      Throws:
        `JsonMappingException`
      Since:
        2.7

    - #### visitArrayFormat

          protected void visitArrayFormat(JsonFormatVisitorWrapper visitor,
                              JavaType typeHint,
                              JsonSerializer<?> itemSerializer,
                              JavaType itemType)
                                   throws JsonMappingException

      Throws:
        `JsonMappingException`
      Since:
        2.7

    - #### visitArrayFormat

          protected void visitArrayFormat(JsonFormatVisitorWrapper visitor,
                              JavaType typeHint,
                              JsonFormatTypes itemType)
                                   throws JsonMappingException

      Throws:
        `JsonMappingException`
      Since:
        2.7

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

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

    - #### findPropertyFilter

          protected PropertyFilter findPropertyFilter(SerializerProvider provider,
                                          java.lang.Object filterId,
                                          java.lang.Object valueToFilter)
                                               throws JsonMappingException

      Helper method used to locate filter that is needed, based on filter id this serializer was constructed with.
      Throws:
        `JsonMappingException`
      Since:
        2.3

    - #### findFormatOverrides

          protected com.fasterxml.jackson.annotation.JsonFormat.Value findFormatOverrides(SerializerProvider provider,
                                                                              BeanProperty prop,
                                                                              java.lang.Class<?> typeForDefaults)

      Helper method that may be used to find if this deserializer has specific `JsonFormat` settings, either via property, or through type-specific defaulting.
      Parameters:
        `typeForDefaults` - Type (erased) used for finding default format settings, if any
      Since:
        2.7

    - #### findFormatFeature

          protected java.lang.Boolean findFormatFeature(SerializerProvider provider,
                                            BeanProperty prop,
                                            java.lang.Class<?> typeForDefaults,
                                            com.fasterxml.jackson.annotation.JsonFormat.Feature feat)

      Convenience method that uses `findFormatOverrides(com.fasterxml.jackson.databind.SerializerProvider, com.fasterxml.jackson.databind.BeanProperty, java.lang.Class<?>)` to find possible defaults and/of overrides, and then calls `JsonFormat.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
      Since:
        2.7

    - #### findIncludeOverrides

          protected com.fasterxml.jackson.annotation.JsonInclude.Value findIncludeOverrides(SerializerProvider provider,
                                                                                BeanProperty prop,
                                                                                java.lang.Class<?> typeForDefaults)

      Since:
        2.8

    - #### findAnnotatedContentSerializer

          protected JsonSerializer<?> findAnnotatedContentSerializer(SerializerProvider serializers,
                                                         BeanProperty property)
                                                              throws JsonMappingException

      Convenience method for finding out possibly configured content value serializer.
      Throws:
        `JsonMappingException`
      Since:
        2.7.4

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