Top Description Fields Constructors Methods
tools.jackson.databind.ser.bean

public Class BeanAsArraySerializer

extends BeanSerializerBase
Class Inheritance
Imports
java.util.Set, tools.jackson.core.JacksonException, .JsonGenerator, .JsonToken, tools.jackson.core.type.WritableTypeId, tools.jackson.databind.*, tools.jackson.databind.jsontype.TypeSerializer, tools.jackson.databind.ser.BeanPropertyWriter, tools.jackson.databind.ser.impl.ObjectIdWriter, tools.jackson.databind.util.NameTransformer

Specialized POJO serializer that differs from tools.jackson.databind.ser.BeanSerializer in that instead of producing a JSON Object it will output a JSON Array, omitting field names, and serializing values in specified serialization order. This behavior is usually triggered by using annotation com.fasterxml.jackson.annotation.JsonFormat or its equivalents.

This serializer can be used for "simple" instances; and will NOT be used if one of following is true:

Note that it is theoretically possible that last 2 issues could be addressed (by reserving room in array, for example); and if so, support improved.

In cases where array-based output is not feasible, this serializer can instead delegate to the original Object-based serializer; this is why a reference is retained to the original serializer.

Field Summary

Modifier and TypeField and Description
protected final BeanSerializerBase
_defaultSerializer

Serializer that would produce JSON Object version; used in cases where array output cannot be used.

Inherited from tools.jackson.databind.ser.bean.BeanSerializerBase:
_beanType_filteredProps_objectIdWriter_propertyFilterId_props_serializationShape_typeIdNAME_FOR_OBJECT_REFNO_PROPS

Constructor Summary

AccessConstructor and Description
public
protected
protected

Method Summary

Modifier and TypeMethod and Description
protected BeanSerializerBase
asArraySerializer()

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.asArraySerializer.

Mutant factory for creating a variant that output POJO as a JSON Array.

public static BeanSerializerBase
private boolean
public boolean
isUnwrappingSerializer()

Overrides tools.jackson.databind.ValueSerializer.isUnwrappingSerializer.

Accessor for checking whether this serializer is an "unwrapping" serializer; this is necessary to know since it may also require caller to suppress writing of the leading property name.

public final void
serialize(Object bean, JsonGenerator gen, SerializationContext provider)

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.serialize.

Main serialization method that will delegate actual output to configured BeanPropertyWriter instances.

protected final void
protected final void
public void
serializeWithType(Object bean, JsonGenerator gen, SerializationContext ctxt, TypeSerializer typeSer)

Overrides tools.jackson.databind.ser.bean.BeanSerializerBase.serializeWithType.

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.

public ValueSerializer<Object>
unwrappingSerializer(NameTransformer transformer)

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.unwrappingSerializer.

Lets force sub-classes to implement this, to avoid accidental missing of handling...

protected BeanAsArraySerializer
withByNameInclusion(Set<String> toIgnore, Set<String> toInclude)

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.withByNameInclusion.

Mutant factory used for creating a new instance with additional set of properties to ignore or include (from properties this instance otherwise has)

public BeanSerializerBase
withFilterId(Object filterId)

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.withFilterId.

Mutant factory used for creating a new instance with different filter id (used with JsonFilter annotation)

public BeanSerializerBase
withObjectIdWriter(ObjectIdWriter objectIdWriter)

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.withObjectIdWriter.

Mutant factory used for creating a new instance with different ObjectIdWriter.

protected BeanSerializerBase
withProperties(BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties)

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.withProperties.

Mutant factory used for creating a new instance with modified set of properties

Inherited from tools.jackson.databind.ser.bean.BeanSerializerBase:
_serializeObjectId_serializeProperties_serializePropertiesFiltered_serializePropertiesMaybeView_serializePropertiesNoView_serializeWithObjectId_serializeWithObjectId_typeIdDefacceptJsonFormatVisitorcanCreateArraySerializercreateContextualfindConvertingSerializergetFilterIdhasViewPropertiespropertiespropertyCountresolvetoStringusesObjectId

Field Detail

_defaultSerializerback to summary
protected final BeanSerializerBase _defaultSerializer

Serializer that would produce JSON Object version; used in cases where array output cannot be used.

Constructor Detail

BeanAsArraySerializerback to summary
public BeanAsArraySerializer(BeanSerializerBase src)
BeanAsArraySerializerback to summary
protected BeanAsArraySerializer(BeanSerializerBase src, Set<String> toIgnore, Set<String> toInclude)
BeanAsArraySerializerback to summary
protected BeanAsArraySerializer(BeanSerializerBase src, ObjectIdWriter oiw, Object filterId)

Method Detail

asArraySerializerback to summary
protected BeanSerializerBase asArraySerializer()

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.asArraySerializer.

Doc from tools.jackson.databind.ser.bean.BeanSerializerBase.asArraySerializer.

Mutant factory for creating a variant that output POJO as a JSON Array. Implementations may ignore this request if output as array is not possible (either at all, or reliably).

Annotations
@Override
constructback to summary
public static BeanSerializerBase construct(BeanSerializerBase src)
Since
3.0
hasSingleElementback to summary
private boolean hasSingleElement(SerializationContext provider)
isUnwrappingSerializerback to summary
public boolean isUnwrappingSerializer()

Overrides tools.jackson.databind.ValueSerializer.isUnwrappingSerializer.

Doc from tools.jackson.databind.ValueSerializer.isUnwrappingSerializer.

Accessor for checking whether this serializer is an "unwrapping" serializer; this is necessary to know since it may also require caller to suppress writing of the leading property name.

Annotations
@Override
serializeback to summary
public final void serialize(Object bean, JsonGenerator gen, SerializationContext provider) throws JacksonException

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.serialize.

Main serialization method that will delegate actual output to configured BeanPropertyWriter instances.

Annotations
@Override
serializeFilteredback to summary
protected final void serializeFiltered(Object bean, JsonGenerator gen, SerializationContext provider) throws JacksonException
serializeNonFilteredback to summary
protected final void serializeNonFiltered(Object bean, JsonGenerator gen, SerializationContext provider) throws JacksonException
serializeWithTypeback to summary
public void serializeWithType(Object bean, JsonGenerator gen, SerializationContext ctxt, TypeSerializer typeSer) throws JacksonException

Overrides tools.jackson.databind.ser.bean.BeanSerializerBase.serializeWithType.

Doc from tools.jackson.databind.ValueSerializer.serializeWithType.

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.
Annotations
@Override
unwrappingSerializerback to summary
public ValueSerializer<Object> unwrappingSerializer(NameTransformer transformer)

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.unwrappingSerializer.

Doc from tools.jackson.databind.ser.bean.BeanSerializerBase.unwrappingSerializer.

Lets force sub-classes to implement this, to avoid accidental missing of handling...

Annotations
@Override
withByNameInclusionback to summary
protected BeanAsArraySerializer withByNameInclusion(Set<String> toIgnore, Set<String> toInclude)

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.withByNameInclusion.

Doc from tools.jackson.databind.ser.bean.BeanSerializerBase.withByNameInclusion.

Mutant factory used for creating a new instance with additional set of properties to ignore or include (from properties this instance otherwise has)

Annotations
@Override
withFilterIdback to summary
public BeanSerializerBase withFilterId(Object filterId)

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.withFilterId.

Doc from tools.jackson.databind.ser.bean.BeanSerializerBase.withFilterId.

Mutant factory used for creating a new instance with different filter id (used with JsonFilter annotation)

Annotations
@Override
withObjectIdWriterback to summary
public BeanSerializerBase withObjectIdWriter(ObjectIdWriter objectIdWriter)

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.withObjectIdWriter.

Doc from tools.jackson.databind.ser.bean.BeanSerializerBase.withObjectIdWriter.

Mutant factory used for creating a new instance with different ObjectIdWriter.

Annotations
@Override
withPropertiesback to summary
protected BeanSerializerBase withProperties(BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties)

Implements abstract tools.jackson.databind.ser.bean.BeanSerializerBase.withProperties.

Doc from tools.jackson.databind.ser.bean.BeanSerializerBase.withProperties.

Mutant factory used for creating a new instance with modified set of properties

Annotations
@Override