Class CollectionSerializer

All Implemented Interfaces:
JsonFormatVisitable

public class CollectionSerializer extends AsArraySerializerBase<Collection<?>>
Fallback serializer for cases where Collection is not known to be of type for which more specializer serializer exists (such as index-accessible List). If so, we will just construct an Iterator to iterate over elements.
  • Field Details

    • _maybeEnumSet

      private final boolean _maybeEnumSet
      Flag that indicates that we may need to check for EnumSet dynamically during serialization: problem being that we can't always do it statically. But we can figure out when there is a possibility wrt type signature we get.
  • Constructor Details

  • Method Details

    • _withValueTypeSerializer

      protected StdContainerSerializer<?> _withValueTypeSerializer(TypeSerializer vts)
      Description copied from class: StdContainerSerializer
      Method that needs to be implemented to allow construction of a new serializer object with given TypeSerializer, used when addition type information is to be embedded.
      Specified by:
      _withValueTypeSerializer in class StdContainerSerializer<Collection<?>>
    • withResolved

      protected CollectionSerializer withResolved(BeanProperty property, TypeSerializer vts, ValueSerializer<?> elementSerializer, Boolean unwrapSingle, Object suppressableValue, boolean suppressNulls)
      Description copied from class: AsArraySerializerBase
      Factory method to use for creating differently configured instances, called by this class (from #createContextual), overridden by implementation class.

      NOTE: only implemented for backwards-compatibility with 3.0 version JacksonModules, otherwise would be abstract: sub-classes really need to override.

      Overrides:
      withResolved in class AsArraySerializerBase<Collection<?>>
    • isEmpty

      public boolean isEmpty(SerializationContext prov, Collection<?> value)
      Description copied from class: ValueSerializer
      Method called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values).

      Default implementation will consider only null values to be empty.

      Specified by:
      isEmpty in class StdContainerSerializer<Collection<?>>
    • hasSingleElement

      public boolean hasSingleElement(Collection<?> value)
      Description copied from class: StdContainerSerializer
      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 this method is only called by serializer itself; and specifically is not used for non-array/collection types like Map or Map.Entry instances.

      Specified by:
      hasSingleElement in class StdContainerSerializer<Collection<?>>
    • serialize

      public final void serialize(Collection<?> value, tools.jackson.core.JsonGenerator g, SerializationContext ctxt) 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 StdSerializer<Collection<?>>
      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.
      Throws:
      tools.jackson.core.JacksonException
    • serializeContents

      public void serializeContents(Collection<?> value, tools.jackson.core.JsonGenerator g, SerializationContext ctxt) throws tools.jackson.core.JacksonException
      Specified by:
      serializeContents in class AsArraySerializerBase<Collection<?>>
      Throws:
      tools.jackson.core.JacksonException
    • serializeContentsImpl

      private void serializeContentsImpl(Collection<?> value, tools.jackson.core.JsonGenerator g, SerializationContext ctxt) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • serializeContentsUsingImpl

      private void serializeContentsUsingImpl(Collection<?> value, tools.jackson.core.JsonGenerator g, SerializationContext ctxt, ValueSerializer<Object> ser) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException