Class ContainerSerializer<T>

All Implemented Interfaces:
JsonFormatVisitable, SchemaAware, Serializable
Direct Known Subclasses:
ArraySerializerBase, AsArraySerializerBase, MapEntrySerializer, MapSerializer

public abstract class ContainerSerializer<T> extends StdSerializer<T>
Intermediate base class for serializers used for serializing types that contain element(s) of other types, such as arrays, Collections (Lists, Sets etc) and Maps and iterable things (Iterators).
See Also:
  • Method Details

    • withValueTypeSerializer

      public ContainerSerializer<?> withValueTypeSerializer(TypeSerializer vts)
      Factory(-like) method that can be used to construct a new container serializer that uses specified TypeSerializer for decorating contained values with additional type information.
      Parameters:
      vts - Type serializer to use for contained values; can be null, in which case 'this' serializer is returned as is
      Returns:
      Serializer instance that uses given type serializer for values if that is possible (or if not, just 'this' serializer)
    • getContentType

      public abstract JavaType getContentType()
      Accessor for finding declared (static) element type for type this serializer is used for.
    • getContentSerializer

      public abstract JsonSerializer<?> getContentSerializer()
      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 getContentType() and SerializerProvider.findContentValueSerializer(com.fasterxml.jackson.databind.JavaType, com.fasterxml.jackson.databind.BeanProperty).
    • hasSingleElement

      public abstract boolean hasSingleElement(T value)
      Method called to determine if the given value (of type handled by this serializer) contains exactly one element.

      Note: although it might seem sensible to instead define something like "getElementCount()" method, this would not work well for containers that do not keep track of size (like linked lists may not).

      Note, too, that as of now (2.9) this method is only called by serializer itself; and specifically is not used for non-array/collection types like Map or Map.Entry instances.