Class AsArraySerializerBase<T>

All Implemented Interfaces:
JsonFormatVisitable
Direct Known Subclasses:
CollectionSerializer, EnumSetSerializer, IndexedListSerializer, IterableSerializer, IteratorSerializer

public abstract class AsArraySerializerBase<T> extends StdContainerSerializer<T>
Base class for serializers that will output contents as JSON arrays; typically serializers used for Collection and array types.
  • Field Details

    • _elementType

      protected final JavaType _elementType
    • _staticTyping

      protected final boolean _staticTyping
    • _unwrapSingle

      protected final Boolean _unwrapSingle
      Setting for specific local override for "unwrap single element arrays": true for enable unwrapping, false for preventing it, `null` for using global configuration.
    • _valueTypeSerializer

      protected final TypeSerializer _valueTypeSerializer
      Type serializer used for values, if any.
    • _elementSerializer

      protected final ValueSerializer<Object> _elementSerializer
      Value serializer to use, if it can be statically determined
  • Constructor Details

  • Method Details

    • withResolved

      protected abstract AsArraySerializerBase<T> withResolved(BeanProperty property, TypeSerializer vts, ValueSerializer<?> elementSerializer, Boolean unwrapSingle)
    • createContextual

      public ValueSerializer<?> createContextual(SerializationContext ctxt, BeanProperty property)
      This method is needed to resolve contextual annotations like per-property overrides, as well as do recursive call to createContextual of content serializer, if known statically.
      Overrides:
      createContextual in class ValueSerializer<T>
      Parameters:
      ctxt - Context to use for accessing config, other serializers
      property - Property (defined by one or more accessors - field or method - used for accessing logical property value) for which serializer is used to be used; or, `null` for root value (or in cases where caller does not have this information, which is handled as root value case).
      Returns:
      Serializer to use for serializing values of specified property; may be this instance or a new instance.
    • getContentType

      public JavaType getContentType()
      Description copied from class: StdContainerSerializer
      Accessor for finding declared (static) element type for type this serializer is used for.
      Specified by:
      getContentType in class StdContainerSerializer<T>
    • getContentSerializer

      public ValueSerializer<?> getContentSerializer()
      Description copied from class: StdContainerSerializer
      Accessor for serializer used for serializing contents (List and array elements, Map values etc) of the container for which this serializer is used, if it is known statically. Note that for dynamic types this may return null; if so, caller has to instead use StdContainerSerializer.getContentType() and SerializationContext.findContentValueSerializer(tools.jackson.databind.JavaType, tools.jackson.databind.BeanProperty).
      Specified by:
      getContentSerializer in class StdContainerSerializer<T>
    • serializeWithType

      public void serializeWithType(T value, tools.jackson.core.JsonGenerator g, SerializationContext ctxt, TypeSerializer typeSer) 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, using specified type serializer for embedding necessary type information.

      Default implementation will throw UnsupportedOperationException to indicate that proper type handling needs to be implemented.

      For simple datatypes written as a single scalar value (JSON String, Number, Boolean), implementation would look like:

        // note: method to call depends on whether this type is serialized as JSON scalar, object or Array!
        typeSer.writeTypePrefixForScalar(value, gen);
        serialize(value, gen, provider);
        typeSer.writeTypeSuffixForScalar(value, gen);
      
      and implementations for type serialized as JSON Arrays or Objects would differ slightly, as START-ARRAY/END-ARRAY and START-OBJECT/END-OBJECT pairs need to be properly handled with respect to serializing of contents.
      Overrides:
      serializeWithType in class ValueSerializer<T>
      Parameters:
      value - Value to serialize; can not be null.
      g - Generator used to output resulting Json content
      ctxt - Context that can be used to get serializers for serializing Objects value contains, if any.
      typeSer - Type serializer to use for including type information
      Throws:
      tools.jackson.core.JacksonException
    • serializeContents

      protected abstract void serializeContents(T value, tools.jackson.core.JsonGenerator gen, SerializationContext provider) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • acceptJsonFormatVisitor

      public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws tools.jackson.core.JacksonException
      Description copied from class: StdSerializer
      Default implementation specifies no format. This behavior is usually overriden by custom serializers.
      Specified by:
      acceptJsonFormatVisitor in interface JsonFormatVisitable
      Overrides:
      acceptJsonFormatVisitor in class StdSerializer<T>
      typeHint - Type of element (entity like property) being visited
      Throws:
      tools.jackson.core.JacksonException