Class StdSerializer<T>

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, FailingSerializer, IntStreamSerializer, JacksonSerializableSerializer, Jdk8StreamSerializer, JDKArraySerializers.CharArraySerializer, JDKKeySerializers.Default, JDKKeySerializers.Dynamic, JDKKeySerializers.EnumKeySerializer, JDKKeySerializers.StringKeySerializer, JDKStringLikeSerializer, LongStreamSerializer, MapEntryAsPOJOSerializer, NullSerializer, QNameSerializer, RawSerializer, StaticListSerializerBase, StdContainerSerializer, StdDelegatingSerializer, StdDynamicSerializer, StdScalarSerializer, ToEmptyObjectSerializer, TokenBufferSerializer, ToStringSerializerBase, UnsupportedTypeSerializer, XMLGregorianCalendarSerializer

public abstract class StdSerializer<T> extends ValueSerializer<T> implements JsonFormatVisitable
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).
  • Field Details

    • _handledType

      protected final Class<?> _handledType
      Nominal type supported, usually declared type of property for which serializer is used.
  • Constructor Details

    • StdSerializer

      protected StdSerializer(Class<?> t)
    • StdSerializer

      protected StdSerializer(JavaType type)
    • StdSerializer

      @Deprecated protected StdSerializer(Class<?> t, boolean dummy)
      Deprecated.
      Alternate constructor that is (alas!) needed to work around kinks of generic type handling
    • StdSerializer

      protected StdSerializer(StdSerializer<?> src)
  • Method Details

    • handledType

      public Class<?> 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 class ValueSerializer<T>
    • serialize

      public abstract void serialize(T value, tools.jackson.core.JsonGenerator gen, SerializationContext provider) throws tools.jackson.core.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 class ValueSerializer<T>
      Parameters:
      value - Value to serialize; can not be null.
      gen - Generator used to output resulting Json content
      provider - Context that can be used to get serializers for serializing Objects value contains, if any.
      Throws:
      tools.jackson.core.JacksonException
    • acceptJsonFormatVisitor

      public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
      Default implementation specifies no format. This behavior is usually overriden by custom serializers.
      Specified by:
      acceptJsonFormatVisitor in interface JsonFormatVisitable
      Overrides:
      acceptJsonFormatVisitor in class ValueSerializer<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

      protected ObjectNode createSchemaNode(String type)
    • createSchemaNode

      protected ObjectNode createSchemaNode(String type, boolean isOptional)
    • visitStringFormat

      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.
    • 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, tools.jackson.core.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, tools.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.
    • visitFloatFormat

      protected void visitFloatFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, tools.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.
    • 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 provider, Throwable t, Object bean, String fieldName) throws tools.jackson.core.JacksonException
      Method that will modify caught exception (passed in as argument) as necessary to include reference information, and to ensure it is a subtype of JacksonException, 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 IOExceptions are unpeeled
      Throws:
      tools.jackson.core.JacksonException
    • wrapAndThrow

      public void wrapAndThrow(SerializationContext provider, Throwable t, Object bean, int index) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.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 specific JsonFormat 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 uses findFormatOverrides(tools.jackson.databind.SerializationContext, tools.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
    • 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

      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. Determination is done using JacksonStdImpl annotation on serializer class.
    • _neitherNull

      protected static final boolean _neitherNull(Object a, Object b)
    • _nonEmpty

      protected static final boolean _nonEmpty(Collection<?> c)
    • _wrapIOFailure

      protected tools.jackson.core.JacksonException _wrapIOFailure(SerializationContext ctxt, IOException e)