Top Description Fields Constructors Methods
com.fasterxml.jackson.databind.ser.std

public abstract Class BeanSerializerBase

extends StdSerializer<Object>
implements ContextualSerializer, ResolvableSerializer, JsonFormatVisitable
Class Inheritance
All Implemented Interfaces
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable, com.fasterxml.jackson.databind.ser.ResolvableSerializer, com.fasterxml.jackson.databind.ser.ContextualSerializer
Known Direct Subclasses
com.fasterxml.jackson.databind.ser.BeanSerializer, com.fasterxml.jackson.databind.ser.impl.BeanAsArraySerializer, com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanSerializer
Annotations
@SuppressWarnings:serial
Imports
java.io.IOException, java.lang.reflect.Type, java.util.*, com.fasterxml.jackson.annotation.*, com.fasterxml.jackson.core.*, com.fasterxml.jackson.core.type.WritableTypeId, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.introspect.AnnotatedMember, .ObjectIdInfo, com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable, .JsonFormatVisitorWrapper, .JsonObjectFormatVisitor, com.fasterxml.jackson.databind.jsontype.TypeSerializer, com.fasterxml.jackson.databind.node.ObjectNode, com.fasterxml.jackson.databind.ser.*, com.fasterxml.jackson.databind.ser.impl.MapEntrySerializer, .ObjectIdWriter, .PropertyBasedObjectIdGenerator, .WritableObjectId, com.fasterxml.jackson.databind.util.ArrayBuilders, .ClassUtil, .Converter, .IgnorePropertiesUtil, .NameTransformer

References Deprecated

StdSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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 AnyGetterWriter
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 com.fasterxml.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, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties)
References Deprecated BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

protected
BeanSerializerBase(BeanSerializerBase src, ObjectIdWriter objectIdWriter)
References Deprecated BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

protected
BeanSerializerBase(BeanSerializerBase src, ObjectIdWriter objectIdWriter, Object filterId)
References Deprecated BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

protected
BeanSerializerBase(BeanSerializerBase src, String[] toIgnore)
Deprecated

protected
BeanSerializerBase(BeanSerializerBase src, Set<String> toIgnore)
Deprecated

protected
BeanSerializerBase(BeanSerializerBase src, Set<String> toIgnore, Set<String> toInclude)
References Deprecated BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

protected
BeanSerializerBase(BeanSerializerBase src)
References Deprecated BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

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

protected
BeanSerializerBase(BeanSerializerBase src, NameTransformer unwrapper)
References Deprecated BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

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

Method Summary

Modifier and TypeMethod and Description
protected final String
_customTypeId(Object bean)
Deprecated

protected void
protected final void
_serializeWithObjectId(Object bean, JsonGenerator gen, SerializerProvider provider, boolean startEndObject)

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

public void
acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType
Type of element (entity like property) being visited
typeHint
)

Overrides com.fasterxml.jackson.databind.ser.std.StdSerializer.acceptJsonFormatVisitor.

Implements com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Get the representation of the schema to which this serializer will conform.

protected abstract BeanSerializerBase
asArraySerializer()
References Deprecated BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

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

public JsonSerializer<?>
createContextual(SerializerProvider
Serializer provider to use for accessing config, other serializers
provider
,
BeanProperty
Method or field that represents the property (and is used to access value to serialize). Should be available; but there may be cases where caller cannot provide it and null is passed instead (in which case impls usually pass 'this' serializer as is)
property
)

Implements com.fasterxml.jackson.databind.ser.ContextualSerializer.createContextual.

Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property.

protected JsonSerializer<Object>
findConvertingSerializer(SerializerProvider 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 JsonNode
getSchema(SerializerProvider
The serializer provider.
provider
,
Type
A hint about the type.
typeHint
)

Overrides com.fasterxml.jackson.databind.ser.std.StdSerializer.getSchema.

Implements com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Deprecated

Default implementation simply claims type is "string"; usually overriden by custom serializers.

public Iterator<PropertyWriter>
properties()

Overrides com.fasterxml.jackson.databind.JsonSerializer.properties.

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

private static final BeanPropertyWriter[]
public void
resolve(SerializerProvider
Provider that has constructed serializer this method is called on.
provider
)

Implements com.fasterxml.jackson.databind.ser.ResolvableSerializer.resolve.

We need to implement ResolvableSerializer to be able to properly handle cyclic type references.

public abstract void
serialize(Object
Value to serialize; can not be null.
bean
,
JsonGenerator
Generator used to output resulting Json content
gen
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
)

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

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

protected void
protected void
serializeFieldsFiltered(Object bean, JsonGenerator gen, SerializerProvider provider)

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)

public void
serializeWithType(Object
Value to serialize; can not be null.
bean
,
JsonGenerator
Generator used to output resulting Json content
gen
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
,
TypeSerializer
Type serializer to use for including type information
typeSer
)

Overrides com.fasterxml.jackson.databind.JsonSerializer.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 boolean
usesObjectId()

Overrides com.fasterxml.jackson.databind.JsonSerializer.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)
References Deprecated BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

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 com.fasterxml.jackson.databind.JsonSerializer.withFilterId.

References Deprecated BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

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

protected BeanSerializerBase
withIgnorals(Set<String> toIgnore)
Deprecated Since 2.12

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

protected BeanSerializerBase
withIgnorals(String[] toIgnore)
Deprecated since 2.8

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

public abstract BeanSerializerBase
withObjectIdWriter(ObjectIdWriter objectIdWriter)
References Deprecated BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

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

protected abstract BeanSerializerBase
withProperties(BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties)
References Deprecated BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

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

Inherited from com.fasterxml.jackson.databind.ser.std.StdSerializer:
_neitherNull_nonEmptycreateSchemaNodecreateSchemaNodefindAnnotatedContentSerializerfindContextualConvertingSerializerfindConvertingContentSerializerfindFormatFeaturefindFormatOverridesfindIncludeOverridesfindPropertyFiltergetSchemahandledTypeisDefaultSerializervisitArrayFormatvisitArrayFormatvisitFloatFormatvisitIntFormatvisitIntFormatvisitStringFormatvisitStringFormatwrapAndThrowwrapAndThrow

Field Detail

_anyGetterWriterback to summary
protected final AnyGetterWriter _anyGetterWriter

Handler for com.fasterxml.jackson.annotation.JsonAnyGetter annotated properties

_beanTypeback to summary
protected final JavaType _beanType
Since
2.9
_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, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties)

References Deprecated

BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

BeanSerializerBaseback to summary
protected BeanSerializerBase(BeanSerializerBase src, ObjectIdWriter objectIdWriter)

References Deprecated

BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

BeanSerializerBaseback to summary
protected BeanSerializerBase(BeanSerializerBase src, ObjectIdWriter objectIdWriter, Object filterId)

References Deprecated

BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Since
2.3
BeanSerializerBaseback to summary
protected BeanSerializerBase(BeanSerializerBase src, String[] toIgnore)

Deprecated

Annotations
@Deprecated
BeanSerializerBaseback to summary
protected BeanSerializerBase(BeanSerializerBase src, Set<String> toIgnore)

Deprecated

Annotations
@Deprecated
BeanSerializerBaseback to summary
protected BeanSerializerBase(BeanSerializerBase src, Set<String> toIgnore, Set<String> toInclude)

References Deprecated

BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

BeanSerializerBaseback to summary
protected BeanSerializerBase(BeanSerializerBase src)

References Deprecated

BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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, NameTransformer unwrapper)

References Deprecated

BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

Method Detail

_customTypeIdback to summary
protected final String _customTypeId(Object bean)

Deprecated

Annotations
@Deprecated
_serializeObjectIdback to summary
protected void _serializeObjectId(Object bean, JsonGenerator g, SerializerProvider provider, TypeSerializer typeSer, WritableObjectId objectId) throws IOException
_serializeWithObjectIdback to summary
protected final void _serializeWithObjectId(Object bean, JsonGenerator gen, SerializerProvider provider, boolean startEndObject) throws IOException
_serializeWithObjectIdback to summary
protected final void _serializeWithObjectId(Object bean, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException
_typeIdDefback to summary
protected final WritableTypeId _typeIdDef(TypeSerializer typeSer, Object bean, JsonToken valueShape)
Since
2.9
acceptJsonFormatVisitorback to summary
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException

Overrides com.fasterxml.jackson.databind.ser.std.StdSerializer.acceptJsonFormatVisitor.

Implements com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Doc from com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Get the representation of the schema to which this serializer will conform.

Parameters
typeHint:JavaType

Type of element (entity like property) being visited

Annotations
@Override
asArraySerializerback to summary
protected abstract BeanSerializerBase asArraySerializer()

References Deprecated

BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

Since
2.1
createContextualback to summary
public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property) throws JsonMappingException

Implements com.fasterxml.jackson.databind.ser.ContextualSerializer.createContextual.

Doc from com.fasterxml.jackson.databind.ser.ContextualSerializer.createContextual.

Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property. 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.

Parameters
provider:SerializerProvider

Serializer provider to use for accessing config, other serializers

property:BeanProperty

Method or field that represents the property (and is used to access value to serialize). Should be available; but there may be cases where caller cannot provide it and null is passed instead (in which case impls usually pass 'this' serializer as is)

Returns:JsonSerializer<?>

Serializer to use for serializing values of specified property; may be this instance or a new instance.

Annotations
@SuppressWarnings:incomplete-switch
@Override
findConvertingSerializerback to summary
protected JsonSerializer<Object> findConvertingSerializer(SerializerProvider provider, BeanPropertyWriter prop) throws JsonMappingException

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

Since
2.2
getSchemaback to summary
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException

Overrides com.fasterxml.jackson.databind.ser.std.StdSerializer.getSchema.

Implements com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Doc from com.fasterxml.jackson.databind.ser.std.StdSerializer.getSchema.

Deprecated

Default implementation simply claims type is "string"; usually overriden by custom serializers.

Parameters
provider:SerializerProvider

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

The serializer provider.

typeHint:Type

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

A hint about the type.

Returns:JsonNode

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Json-schema for this serializer.

Annotations
@Deprecated
@Override
propertiesback to summary
public Iterator<PropertyWriter> properties()

Overrides com.fasterxml.jackson.databind.JsonSerializer.properties.

Doc from com.fasterxml.jackson.databind.JsonSerializer.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 com.fasterxml.jackson.databind.ser.BeanPropertyWriter. Of standard Jackson serializers, only com.fasterxml.jackson.databind.ser.BeanSerializer exposes properties.

Annotations
@Override
renameback to summary
private static final BeanPropertyWriter[] rename(BeanPropertyWriter[] props, NameTransformer transformer)
resolveback to summary
public void resolve(SerializerProvider provider) throws JsonMappingException

Implements com.fasterxml.jackson.databind.ser.ResolvableSerializer.resolve.

We need to implement ResolvableSerializer to be able to properly handle cyclic type references.

Parameters
provider:SerializerProvider

Doc from com.fasterxml.jackson.databind.ser.ResolvableSerializer.resolve.

Provider that has constructed serializer this method is called on.

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

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Doc from com.fasterxml.jackson.databind.JsonSerializer.serialize.

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

Parameters
bean:Object

Value to serialize; can not be null.

gen:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

Annotations
@Override
serializeFieldsback to summary
protected void serializeFields(Object bean, JsonGenerator gen, SerializerProvider provider) throws IOException
serializeFieldsFilteredback to summary
protected void serializeFieldsFiltered(Object bean, JsonGenerator gen, SerializerProvider provider) throws IOException

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)

serializeWithTypeback to summary
public void serializeWithType(Object bean, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException

Overrides com.fasterxml.jackson.databind.JsonSerializer.serializeWithType.

Doc from com.fasterxml.jackson.databind.JsonSerializer.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.
Parameters
bean:Object

Value to serialize; can not be null.

gen:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

typeSer:TypeSerializer

Type serializer to use for including type information

Annotations
@Override
usesObjectIdback to summary
public boolean usesObjectId()

Overrides com.fasterxml.jackson.databind.JsonSerializer.usesObjectId.

Doc from com.fasterxml.jackson.databind.JsonSerializer.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)

References Deprecated

BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

Since
2.12
withFilterIdback to summary
public abstract BeanSerializerBase withFilterId(Object filterId)

Overrides com.fasterxml.jackson.databind.JsonSerializer.withFilterId.

References Deprecated

BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

Annotations
@Override
Since
2.3
withIgnoralsback to summary
protected BeanSerializerBase withIgnorals(Set<String> toIgnore)

Deprecated

Since 2.12

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

Annotations
@Deprecated
Since
2.8
withIgnoralsback to summary
protected BeanSerializerBase withIgnorals(String[] toIgnore)

Deprecated

since 2.8

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

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

References Deprecated

BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

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

References Deprecated

BeanSerializerBase is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

Note

in 2.11.x, need to keep non-abstract for slightly better compatibility (XML module extends)

Since
2.11.1