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

public abstract Class BeanSerializerBase

extends StdSerializer<Object>
Class Inheritance
Known Direct Subclasses
tools.jackson.databind.ser.bean.UnrolledBeanAsArraySerializer, tools.jackson.databind.ser.bean.UnwrappingBeanSerializer, tools.jackson.databind.ser.BeanSerializer, tools.jackson.databind.ser.UnrolledBeanSerializer, tools.jackson.databind.ser.bean.BeanAsArraySerializer
Imports
java.util.*, com.fasterxml.jackson.annotation.*, tools.jackson.core.*, tools.jackson.core.type.WritableTypeId, tools.jackson.databind.*, tools.jackson.databind.introspect.AnnotatedMember, .ObjectIdInfo, tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper, .JsonObjectFormatVisitor, tools.jackson.databind.jsontype.TypeSerializer, tools.jackson.databind.ser.*, tools.jackson.databind.ser.impl.ObjectIdWriter, .PropertyBasedObjectIdGenerator, tools.jackson.databind.ser.jdk.EnumSerializer, .MapEntrySerializer, tools.jackson.databind.ser.std.StdContainerSerializer, .StdDelegatingSerializer, .StdSerializer, tools.jackson.databind.util.ClassUtil, .Converter, .IgnorePropertiesUtil, .NameTransformer

Base class both for the standard bean serializer, and couple of variants that only differ in small details. Can be used for custom bean serializers as well, although that is not the primary design goal.

Field Summary

Modifier and TypeField and Description
protected final JavaType
protected final BeanPropertyWriter[]
_filteredProps

Optional filters used to suppress output of properties that are only to be included in certain views

protected final ObjectIdWriter
_objectIdWriter

If this POJO can be alternatively serialized using just an object id to denote a reference to previously serialized object, this Object will handle details.

protected final Object
_propertyFilterId

Id of the bean property filter to use, if any; null if none.

protected final BeanPropertyWriter[]
_props

Writers used for outputting actual property values

protected final JsonFormat.Shape
_serializationShape

Requested shape from bean class annotations.

protected final AnnotatedMember
_typeId

If using custom type ids (usually via getter, or field), this is the reference to that member.

protected static final PropertyName
protected static final BeanPropertyWriter[]
Inherited from tools.jackson.databind.ser.std.StdSerializer:
_handledType

Constructor Summary

AccessConstructor and Description
protected
BeanSerializerBase(JavaType
Nominal type of values handled by this serializer
type
,
BeanSerializerBuilder
Builder for accessing other collected information
builder
,
BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties)

Constructor used by BeanSerializerBuilder to create an instance

protected
BeanSerializerBase(BeanSerializerBase src)

Copy-constructor that is useful for sub-classes that just want to copy all super-class properties without modifications.

protected
protected
protected
protected
protected
BeanSerializerBase(BeanSerializerBase src, NameTransformer unwrapper)

Copy-constructor that will also rename properties with given prefix (if it's non-empty)

Method Summary

Modifier and TypeMethod and Description
protected void
protected void
protected void
_serializePropertiesFiltered(Object bean, JsonGenerator g, SerializationContext provider, Object filterId)

Alternative serialization method that gets called when there is a PropertyFilter that needs to be called to determine which properties are to be serialized (and possibly how)

protected void
_serializePropertiesMaybeView(Object bean, JsonGenerator g, SerializationContext provider, BeanPropertyWriter[] props)

Method called when no JSON Filter is to be applied, but View filtering is in effect and so some of properties may be nulls to check.

protected void
_serializePropertiesNoView(Object bean, JsonGenerator gen, SerializationContext provider, BeanPropertyWriter[] props)

Method called when neither JSON Filter is to be applied, nor view-filtering.

protected final void
_serializeWithObjectId(Object bean, JsonGenerator g, SerializationContext provider, boolean startEndObject)

protected final void
protected final WritableTypeId
_typeIdDef(TypeSerializer typeSer, Object bean, JsonToken valueShape)

public void
protected abstract BeanSerializerBase
asArraySerializer()

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

public boolean
canCreateArraySerializer()

Helper method for sub-classes to check if it should be possible to construct an "as-array" serializer.

public ValueSerializer<?>
createContextual(SerializationContext ctxt, BeanProperty property)

Overrides tools.jackson.databind.ValueSerializer.createContextual.

Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property (or, for root values, in which case `null` is passed).

protected ValueSerializer<Object>
findConvertingSerializer(SerializationContext provider, BeanPropertyWriter prop)

Helper method that can be used to see if specified property is annotated to indicate use of a converter for property value (in case of container types, it is container type itself, not key or content type).

public Object
public boolean
hasViewProperties()

Accessor for checking if view-processing is enabled for this bean, that is, if it has separate set of properties with view-checking added.

public Iterator<PropertyWriter>
properties()

Overrides tools.jackson.databind.ValueSerializer.properties.

Accessor for iterating over logical properties that the type handled by this serializer has, from serialization perspective.

public int
private static final BeanPropertyWriter[]
public void
resolve(SerializationContext provider)

Overrides tools.jackson.databind.ValueSerializer.resolve.

We need to resolve dependant serializers here to be able to properly handle cyclic type references.

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

Implements abstract tools.jackson.databind.ser.std.StdSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

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

Overrides 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.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public abstract ValueSerializer<Object>
unwrappingSerializer(NameTransformer unwrapper)

Overrides tools.jackson.databind.ValueSerializer.unwrappingSerializer.

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

public boolean
usesObjectId()

Overrides tools.jackson.databind.ValueSerializer.usesObjectId.

Method that can be called to see whether this serializer instance will use Object Id to handle cyclic references.

protected abstract BeanSerializerBase
withByNameInclusion(Set<String> toIgnore, Set<String> toInclude)

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

public abstract BeanSerializerBase
withFilterId(Object filterId)

Overrides tools.jackson.databind.ValueSerializer.withFilterId.

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

public abstract BeanSerializerBase
withObjectIdWriter(ObjectIdWriter objectIdWriter)

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

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

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

Inherited from tools.jackson.databind.ser.std.StdSerializer:
_neitherNull_nonEmpty_wrapIOFailureacceptJsonFormatVisitorForBinarycreateSchemaNodecreateSchemaNodefindAnnotatedContentSerializerfindContextualConvertingSerializerfindFormatFeaturefindFormatOverridesfindIncludeOverridesfindPropertyFilterhandledTypeisDefaultSerializervisitArrayFormatvisitArrayFormatvisitFloatFormatvisitIntFormatvisitIntFormatvisitStringFormatvisitStringFormatwrapAndThrowwrapAndThrow

Field Detail

_beanTypeback to summary
protected final JavaType _beanType
_filteredPropsback to summary
protected final BeanPropertyWriter[] _filteredProps

Optional filters used to suppress output of properties that are only to be included in certain views

_objectIdWriterback to summary
protected final ObjectIdWriter _objectIdWriter

If this POJO can be alternatively serialized using just an object id to denote a reference to previously serialized object, this Object will handle details.

_propertyFilterIdback to summary
protected final Object _propertyFilterId

Id of the bean property filter to use, if any; null if none.

_propsback to summary
protected final BeanPropertyWriter[] _props

Writers used for outputting actual property values

_serializationShapeback to summary
protected final JsonFormat.Shape _serializationShape

Requested shape from bean class annotations.

_typeIdback to summary
protected final AnnotatedMember _typeId

If using custom type ids (usually via getter, or field), this is the reference to that member.

NAME_FOR_OBJECT_REFback to summary
protected static final PropertyName NAME_FOR_OBJECT_REF
NO_PROPSback to summary
protected static final BeanPropertyWriter[] NO_PROPS

Constructor Detail

BeanSerializerBaseback to summary
protected BeanSerializerBase(JavaType type, BeanSerializerBuilder builder, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties)

Constructor used by BeanSerializerBuilder to create an instance

Parameters
type:JavaType

Nominal type of values handled by this serializer

builder:BeanSerializerBuilder

Builder for accessing other collected information

BeanSerializerBaseback to summary
protected BeanSerializerBase(BeanSerializerBase src)

Copy-constructor that is useful for sub-classes that just want to copy all super-class properties without modifications.

BeanSerializerBaseback to summary
protected BeanSerializerBase(BeanSerializerBase src, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties)
BeanSerializerBaseback to summary
protected BeanSerializerBase(BeanSerializerBase src, ObjectIdWriter objectIdWriter)
BeanSerializerBaseback to summary
protected BeanSerializerBase(BeanSerializerBase src, ObjectIdWriter objectIdWriter, Object filterId)
BeanSerializerBaseback to summary
protected BeanSerializerBase(BeanSerializerBase src, Set<String> toIgnore, Set<String> toInclude)
BeanSerializerBaseback to summary
protected BeanSerializerBase(BeanSerializerBase src, NameTransformer unwrapper)

Copy-constructor that will also rename properties with given prefix (if it's non-empty)

Method Detail

_serializeObjectIdback to summary
protected void _serializeObjectId(Object bean, JsonGenerator g, SerializationContext ctxt, TypeSerializer typeSer, WritableObjectId objectId) throws JacksonException
_serializePropertiesback to summary
protected void _serializeProperties(Object bean, JsonGenerator g, SerializationContext provider) throws JacksonException
_serializePropertiesFilteredback to summary
protected void _serializePropertiesFiltered(Object bean, JsonGenerator g, SerializationContext provider, Object filterId) throws JacksonException

Alternative serialization method that gets called when there is a PropertyFilter that needs to be called to determine which properties are to be serialized (and possibly how)

_serializePropertiesMaybeViewback to summary
protected void _serializePropertiesMaybeView(Object bean, JsonGenerator g, SerializationContext provider, BeanPropertyWriter[] props) throws JacksonException

Method called when no JSON Filter is to be applied, but View filtering is in effect and so some of properties may be nulls to check.

Since
3.0
_serializePropertiesNoViewback to summary
protected void _serializePropertiesNoView(Object bean, JsonGenerator gen, SerializationContext provider, BeanPropertyWriter[] props) throws JacksonException

Method called when neither JSON Filter is to be applied, nor view-filtering. This means that all property writers are non null and can be called directly.

Since
3.0
_serializeWithObjectIdback to summary
protected final void _serializeWithObjectId(Object bean, JsonGenerator g, SerializationContext provider, boolean startEndObject) throws JacksonException
_serializeWithObjectIdback to summary
protected final void _serializeWithObjectId(Object bean, JsonGenerator g, SerializationContext provider, TypeSerializer typeSer) throws JacksonException
_typeIdDefback to summary
protected final WritableTypeId _typeIdDef(TypeSerializer typeSer, Object bean, JsonToken valueShape)
acceptJsonFormatVisitorback to summary
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)

Overrides tools.jackson.databind.ser.std.StdSerializer.acceptJsonFormatVisitor.

Implements tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Doc from tools.jackson.databind.ser.std.StdSerializer.acceptJsonFormatVisitor.

Default implementation specifies no format. This behavior is usually overriden by custom serializers.

Annotations
@Override
asArraySerializerback to summary
protected abstract 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).

canCreateArraySerializerback to summary
public boolean canCreateArraySerializer()

Helper method for sub-classes to check if it should be possible to construct an "as-array" serializer. Returns if all of following hold true:

  • have Object Id (may be allowed in future)
  • have "any getter"
Since
3.0
createContextualback to summary
public ValueSerializer<?> createContextual(SerializationContext ctxt, BeanProperty property)

Overrides tools.jackson.databind.ValueSerializer.createContextual.

Doc from tools.jackson.databind.ValueSerializer.createContextual.

Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property (or, for root values, in which case `null` is passed). Note that instance that this method is called on is typically shared one and as a result method should NOT modify this instance but rather construct and return a new instance. This instance should only be returned as-is, in case it is already suitable for use.

Note that method is only called once per POJO property, and for the first usage as root value serializer; it is not called for every serialization, as doing that would have significant performance impact; most serializers cache contextual instances for future use.

Annotations
@SuppressWarnings:incomplete-switch
@Override
findConvertingSerializerback to summary
protected ValueSerializer<Object> findConvertingSerializer(SerializationContext provider, BeanPropertyWriter prop)

Helper method that can be used to see if specified property is annotated to indicate use of a converter for property value (in case of container types, it is container type itself, not key or content type).

getFilterIdback to summary
public Object getFilterId()
Since
3.0
hasViewPropertiesback to summary
public boolean hasViewProperties()

Accessor for checking if view-processing is enabled for this bean, that is, if it has separate set of properties with view-checking added.

Since
3.0
propertiesback to summary
public Iterator<PropertyWriter> properties()

Overrides tools.jackson.databind.ValueSerializer.properties.

Doc from tools.jackson.databind.ValueSerializer.properties.

Accessor for iterating over logical properties that the type handled by this serializer has, from serialization perspective. Actual type of properties, if any, will be tools.jackson.databind.ser.BeanPropertyWriter. Of standard Jackson serializers, only tools.jackson.databind.ser.BeanSerializer exposes properties.

Annotations
@Override
propertyCountback to summary
public int propertyCount()
Since
3.0
renameback to summary
private static final BeanPropertyWriter[] rename(BeanPropertyWriter[] props, NameTransformer transformer)
resolveback to summary
public void resolve(SerializationContext provider)

Overrides tools.jackson.databind.ValueSerializer.resolve.

We need to resolve dependant serializers here to be able to properly handle cyclic type references.

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

Implements abstract tools.jackson.databind.ser.std.StdSerializer.serialize.

Doc from tools.jackson.databind.ValueSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Annotations
@Override
serializeWithTypeback to summary
public void serializeWithType(Object bean, JsonGenerator gen, SerializationContext ctxt, TypeSerializer typeSer) throws JacksonException

Overrides tools.jackson.databind.ValueSerializer.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
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
unwrappingSerializerback to summary
public abstract ValueSerializer<Object> unwrappingSerializer(NameTransformer unwrapper)

Overrides tools.jackson.databind.ValueSerializer.unwrappingSerializer.

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

Annotations
@Override
usesObjectIdback to summary
public boolean usesObjectId()

Overrides tools.jackson.databind.ValueSerializer.usesObjectId.

Doc from tools.jackson.databind.ValueSerializer.usesObjectId.

Method that can be called to see whether this serializer instance will use Object Id to handle cyclic references.

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

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

withFilterIdback to summary
public abstract BeanSerializerBase withFilterId(Object filterId)

Overrides tools.jackson.databind.ValueSerializer.withFilterId.

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

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

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

withPropertiesback to summary
protected abstract BeanSerializerBase withProperties(BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties)

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