com.fasterxml.jackson.databind.ser

## Class BeanPropertyWriter

- java.lang.Object
- - com.fasterxml.jackson.databind.ser.PropertyWriter
  - - com.fasterxml.jackson.databind.ser.BeanPropertyWriter

All Implemented Interfaces:
  BeanProperty, Named

Direct Known Subclasses:
  UnwrappingBeanPropertyWriter

    public class BeanPropertyWriter
    extends PropertyWriter
    implements BeanProperty

Base bean property handler class, which implements common parts of reflection-based functionality for accessing a property value and serializing it.

Note that current design tries to keep instances immutable (semi-functional style); mostly because these instances are exposed to application code and this is to reduce likelihood of data corruption and synchronization issues.

### Nested Class Summary

### Nested classes/interfaces inherited from interface com.fasterxml.jackson.databind.BeanProperty

`BeanProperty.Std`

### Field Summary

Fields
`protected Method` `_accessorMethod` Accessor method used to get property value, for method-accessible properties.
`protected JavaType` `_cfgSerializationType` Type to use for locating serializer; normally same as return type of the accessor method, but may be overridden by annotations.
`protected Annotations` `_contextAnnotations` Annotations from context (most often, class that declares property, or in case of sub-class serializer, from that sub-class)
`protected JavaType` `_declaredType` Type property is declared to have, either in class definition or associated annotations.
`protected PropertySerializerMap` `_dynamicSerializers` In case serializer is not known statically (i.e.
`protected Field` `_field` Field that contains the property value for field-accessible properties.
`protected Class<?>[]` `_includeInViews` Alternate set of property writers used when view-based filtering is available for the Bean.
`protected HashMap<Object,Object>` `_internalSettings`
`protected AnnotatedMember` `_member` Member (field, method) that represents property and allows access to associated annotations.
`protected PropertyMetadata` `_metadata` Additional information about property
`protected SerializedString` `_name` Logical name of the property; will be used as the field name under which value for the property is written.
`protected JavaType` `_nonTrivialBaseType` Base type of the property, if the declared type is "non-trivial"; meaning it is either a structured type (collection, map, array), or parameterized.
`protected JsonSerializer<Object>` `_nullSerializer` Serializer used for writing out null values, if any: if null, null values are to be suppressed.
`protected JsonSerializer<Object>` `_serializer` Serializer to use for writing out the value: null if it can not be known statically; non-null if it can.
`protected Object` `_suppressableValue` Value that is considered default value of the property; used for default-value-suppression if enabled.
`protected boolean` `_suppressNulls` Whether null values are to be suppressed (nothing written out if value is null) or not.
`protected TypeSerializer` `_typeSerializer` If property being serialized needs type information to be included this is the type serializer to use.
`protected PropertyName` `_wrapperName` Wrapper name to use for this element, if any
`static Object` `MARKER_FOR_EMPTY` Marker object used to indicate "do not serialize if empty"

### Constructor Summary

Constructors
`` `BeanPropertyWriter(BeanPropertyDefinition propDef, AnnotatedMember member, Annotations contextAnnotations, JavaType declaredType, JsonSerializer<?> ser, TypeSerializer typeSer, JavaType serType, boolean suppressNulls, Object suppressableValue)`
`protected` `BeanPropertyWriter(BeanPropertyWriter base)` "Copy constructor" to be used by filtering sub-classes
`protected` `BeanPropertyWriter(BeanPropertyWriter base, SerializedString name)`

### Method Summary

Methods
`protected void` `_depositSchemaProperty(ObjectNode propertiesNode, JsonNode schemaNode)`
`protected JsonSerializer<Object>` `_findAndAddDynamic(PropertySerializerMap map, Class<?> type, SerializerProvider provider)`
`protected boolean` `_handleSelfReference(Object bean, JsonGenerator jgen, SerializerProvider prov, JsonSerializer<?> ser)` Method called to handle a direct self-reference through this property.
`protected void` `_handleSelfReference(Object bean, JsonSerializer<?> ser)` Deprecated. Since 2.3 Use overloaded variants
`void` `assignNullSerializer(JsonSerializer<Object> nullSer)` Method called to assign null value serializer for property
`void` `assignSerializer(JsonSerializer<Object> ser)` Method called to assign value serializer for property
`void` `depositSchemaProperty(JsonObjectFormatVisitor v)` Traversal method used for things like JSON Schema generation, or POJO introspection.
`void` `depositSchemaProperty(ObjectNode propertiesNode, SerializerProvider provider)` Deprecated.
`Object` `get(Object bean)` Method that can be used to access value of the property this Object describes, from given bean instance.
`<A extends Annotation> A` `getAnnotation(Class<A> acls)` Method for finding annotation associated with this property; meaning annotation associated with one of entities used to access property.
`<A extends Annotation> A` `getContextAnnotation(Class<A> acls)` Method for finding annotation associated with context of this property; usually class in which member is declared (or its subtype if processing subtype).
`PropertyName` `getFullName()` Method for getting full name definition, including possible format-specific additional properties (such as namespace when using XML backend).
`Type` `getGenericPropertyType()` Get the generic property type of this property writer.
`Object` `getInternalSetting(Object key)` Method for accessing value of specified internal setting.
`AnnotatedMember` `getMember()` Method for accessing primary physical entity that represents the property; annotated field, method or constructor property.
`PropertyMetadata` `getMetadata()` Accessor for additional optional information about property.
`String` `getName()` Method to get logical name of the property
`Class<?>` `getPropertyType()`
`Class<?>` `getRawSerializationType()`
`JavaType` `getSerializationType()`
`SerializableString` `getSerializedName()`
`JsonSerializer<Object>` `getSerializer()`
`JavaType` `getType()` Method to get declared type of the property.
`Class<?>[]` `getViews()`
`PropertyName` `getWrapperName()` If property is indicated to be wrapped, name of wrapper element to use.
`boolean` `hasNullSerializer()`
`boolean` `hasSerializer()`
`boolean` `isRequired()` Whether value for property is marked as required using annotations or associated schema.
`protected boolean` `isRequired(AnnotationIntrospector intr)` Deprecated. since 2.2, use `isRequired()` instead.
`boolean` `isUnwrapping()` Accessor that will return true if this bean property has to support "unwrapping"; ability to replace POJO structural wrapping with optional name prefix and/or suffix (or in some cases, just removal of wrapper name).
`Object` `removeInternalSetting(Object key)` Method for removing entry for specified internal setting.
`BeanPropertyWriter` `rename(NameTransformer transformer)`
`void` `serializeAsElement(Object bean, JsonGenerator jgen, SerializerProvider prov)` Alternative to `serializeAsField(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider)` that is used when a POJO is serialized as JSON Array; the difference is that no field names are written.
`void` `serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider prov)` Method called to access property that this bean stands for, from within given bean, and to serialize it as a JSON Object field using appropriate serializer.
`void` `serializeAsOmittedField(Object bean, JsonGenerator jgen, SerializerProvider prov)` Method called to indicate that serialization of a field was omitted due to filtering, in cases where backend data format does not allow basic omission.
`void` `serializeAsPlaceholder(Object bean, JsonGenerator jgen, SerializerProvider prov)` Method called to serialize a placeholder used in tabular output when real value is not to be included (is filtered out), but when we need an entry so that field indexes will not be off.
`Object` `setInternalSetting(Object key, Object value)` Method for setting specific internal setting to given value
`void` `setNonTrivialBaseType(JavaType t)` Method called to define type to consider as "non-trivial" basetype, needed for dynamic serialization resolution for complex (usually container) types
`String` `toString()`
`BeanPropertyWriter` `unwrappingWriter(NameTransformer unwrapper)` Method called create an instance that handles details of unwrapping contained value.
`boolean` `willSuppressNulls()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### MARKER_FOR_EMPTY

    public static final Object MARKER_FOR_EMPTY

Marker object used to indicate "do not serialize if empty"

#### _member

    protected final AnnotatedMember _member

Member (field, method) that represents property and allows access to associated annotations.

#### _contextAnnotations

    protected final Annotations _contextAnnotations

Annotations from context (most often, class that declares property, or in case of sub-class serializer, from that sub-class)

#### _declaredType

    protected final JavaType _declaredType

Type property is declared to have, either in class definition or associated annotations.

#### _accessorMethod

    protected final Method _accessorMethod

Accessor method used to get property value, for method-accessible properties. Null if and only if `_field` is null.

#### _field

    protected final Field _field

Field that contains the property value for field-accessible properties. Null if and only if `_accessorMethod` is null.

#### _internalSettings

    protected HashMap<Object,Object> _internalSettings

#### _name

    protected final SerializedString _name

Logical name of the property; will be used as the field name under which value for the property is written.

NOTE: do NOT change name of this field; it is accessed by Afterburner module. ALSO NOTE: ... and while it really ought to be `SerializableString`, changing that is also binary-incompatible change. So nope.

#### _wrapperName

    protected final PropertyName _wrapperName

Wrapper name to use for this element, if any

Since:
  2.2

#### _cfgSerializationType

    protected final JavaType _cfgSerializationType

Type to use for locating serializer; normally same as return type of the accessor method, but may be overridden by annotations.

#### _serializer

    protected JsonSerializer<Object> _serializer

Serializer to use for writing out the value: null if it can not be known statically; non-null if it can.

#### _nullSerializer

    protected JsonSerializer<Object> _nullSerializer

Serializer used for writing out null values, if any: if null, null values are to be suppressed.

#### _dynamicSerializers

    protected transient PropertySerializerMap _dynamicSerializers

In case serializer is not known statically (i.e. `_serializer` is null), we will use a lookup structure for storing dynamically resolved mapping from type(s) to serializer(s).

#### _suppressNulls

    protected final boolean _suppressNulls

Whether null values are to be suppressed (nothing written out if value is null) or not.

#### _suppressableValue

    protected final Object _suppressableValue

Value that is considered default value of the property; used for default-value-suppression if enabled.

#### _includeInViews

    protected final Class<?>[] _includeInViews

Alternate set of property writers used when view-based filtering is available for the Bean.

#### _typeSerializer

    protected TypeSerializer _typeSerializer

If property being serialized needs type information to be included this is the type serializer to use. Declared type (possibly augmented with annotations) of property is used for determining exact mechanism to use (compared to actual runtime type used for serializing actual state).

#### _nonTrivialBaseType

    protected JavaType _nonTrivialBaseType

Base type of the property, if the declared type is "non-trivial"; meaning it is either a structured type (collection, map, array), or parameterized. Used to retain type information about contained type, which is mostly necessary if type meta-data is to be included.

#### _metadata

    protected final PropertyMetadata _metadata

Additional information about property

Since:
  2.3

### Constructor Detail

#### BeanPropertyWriter

    public BeanPropertyWriter(BeanPropertyDefinition propDef,
                      AnnotatedMember member,
                      Annotations contextAnnotations,
                      JavaType declaredType,
                      JsonSerializer<?> ser,
                      TypeSerializer typeSer,
                      JavaType serType,
                      boolean suppressNulls,
                      Object suppressableValue)

#### BeanPropertyWriter

    protected BeanPropertyWriter(BeanPropertyWriter base)

"Copy constructor" to be used by filtering sub-classes

#### BeanPropertyWriter

    protected BeanPropertyWriter(BeanPropertyWriter base,
                      SerializedString name)

### Method Detail

#### rename

    public BeanPropertyWriter rename(NameTransformer transformer)

#### assignSerializer

    public void assignSerializer(JsonSerializer<Object> ser)

Method called to assign value serializer for property

Since:
  2.0

#### assignNullSerializer

    public void assignNullSerializer(JsonSerializer<Object> nullSer)

Method called to assign null value serializer for property

Since:
  2.0

#### unwrappingWriter

    public BeanPropertyWriter unwrappingWriter(NameTransformer unwrapper)

Method called create an instance that handles details of unwrapping contained value.

#### setNonTrivialBaseType

    public void setNonTrivialBaseType(JavaType t)

Method called to define type to consider as "non-trivial" basetype, needed for dynamic serialization resolution for complex (usually container) types

#### getName

    public String getName()

Description copied from interface: `BeanProperty`
Method to get logical name of the property

Specified by:
  `getName` in interface `BeanProperty`
Specified by:
  `getName` in interface `Named`
Specified by:
  `getName` in class `PropertyWriter`

#### getFullName

    public PropertyName getFullName()

Description copied from interface: `BeanProperty`
Method for getting full name definition, including possible format-specific additional properties (such as namespace when using XML backend).

Specified by:
  `getFullName` in interface `BeanProperty`
Specified by:
  `getFullName` in class `PropertyWriter`

#### getType

    public JavaType getType()

Description copied from interface: `BeanProperty`
Method to get declared type of the property.

Specified by:
  `getType` in interface `BeanProperty`

#### getWrapperName

    public PropertyName getWrapperName()

Description copied from interface: `BeanProperty`
If property is indicated to be wrapped, name of wrapper element to use.

Specified by:
  `getWrapperName` in interface `BeanProperty`

#### isRequired

    public boolean isRequired()

Description copied from interface: `BeanProperty`
Whether value for property is marked as required using annotations or associated schema.

Specified by:
  `isRequired` in interface `BeanProperty`

#### getMetadata

    public PropertyMetadata getMetadata()

Description copied from interface: `BeanProperty`
Accessor for additional optional information about property.

Specified by:
  `getMetadata` in interface `BeanProperty`
Returns:
  Metadata about property; never null.

#### getAnnotation

    public <A extends Annotation> A getAnnotation(Class<A> acls)

Description copied from interface: `BeanProperty`
Method for finding annotation associated with this property; meaning annotation associated with one of entities used to access property.

Specified by:
  `getAnnotation` in interface `BeanProperty`

#### getContextAnnotation

    public <A extends Annotation> A getContextAnnotation(Class<A> acls)

Description copied from interface: `BeanProperty`
Method for finding annotation associated with context of this property; usually class in which member is declared (or its subtype if processing subtype).

Specified by:
  `getContextAnnotation` in interface `BeanProperty`

#### getMember

    public AnnotatedMember getMember()

Description copied from interface: `BeanProperty`
Method for accessing primary physical entity that represents the property; annotated field, method or constructor property.

Specified by:
  `getMember` in interface `BeanProperty`

#### _depositSchemaProperty

    protected void _depositSchemaProperty(ObjectNode propertiesNode,
                              JsonNode schemaNode)

#### getInternalSetting

    public Object getInternalSetting(Object key)

Method for accessing value of specified internal setting.

Returns:
  Value of the setting, if any; null if none.

#### setInternalSetting

    public Object setInternalSetting(Object key,
                            Object value)

Method for setting specific internal setting to given value

Returns:
  Old value of the setting, if any (null if none)

#### removeInternalSetting

    public Object removeInternalSetting(Object key)

Method for removing entry for specified internal setting.

Returns:
  Existing value of the setting, if any (null if none)

#### getSerializedName

    public SerializableString getSerializedName()

#### hasSerializer

    public boolean hasSerializer()

#### hasNullSerializer

    public boolean hasNullSerializer()

#### isUnwrapping

    public boolean isUnwrapping()

Accessor that will return true if this bean property has to support "unwrapping"; ability to replace POJO structural wrapping with optional name prefix and/or suffix (or in some cases, just removal of wrapper name).

Default implementation simply returns false.

Since:
  2.3

#### willSuppressNulls

    public boolean willSuppressNulls()

#### getSerializer

    public JsonSerializer<Object> getSerializer()

#### getSerializationType

    public JavaType getSerializationType()

#### getRawSerializationType

    public Class<?> getRawSerializationType()

#### getPropertyType

    public Class<?> getPropertyType()

#### getGenericPropertyType

    public Type getGenericPropertyType()

Get the generic property type of this property writer.

Returns:
  The property type, or null if not found.

#### getViews

    public Class<?>[] getViews()

#### isRequired

    @Deprecated
    protected boolean isRequired(AnnotationIntrospector intr)

Deprecated. since 2.2, use `isRequired()` instead.

NOTE: due to introspection, this is a slow method to call and should never be called during actual serialization or filtering of the property. Rather it is needed for traversal needed for things like constructing JSON Schema instances.

Since:
  2.1

#### serializeAsField

    public void serializeAsField(Object bean,
                        JsonGenerator jgen,
                        SerializerProvider prov)
                          throws Exception

Method called to access property that this bean stands for, from within given bean, and to serialize it as a JSON Object field using appropriate serializer.

Specified by:
  `serializeAsField` in class `PropertyWriter`
Throws:
  `Exception`

#### serializeAsOmittedField

    public void serializeAsOmittedField(Object bean,
                               JsonGenerator jgen,
                               SerializerProvider prov)
                                 throws Exception

Method called to indicate that serialization of a field was omitted due to filtering, in cases where backend data format does not allow basic omission.

Specified by:
  `serializeAsOmittedField` in class `PropertyWriter`
Throws:
  `Exception`
Since:
  2.3

#### serializeAsElement

    public void serializeAsElement(Object bean,
                          JsonGenerator jgen,
                          SerializerProvider prov)
                            throws Exception

Alternative to `serializeAsField(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider)` that is used when a POJO is serialized as JSON Array; the difference is that no field names are written.

Specified by:
  `serializeAsElement` in class `PropertyWriter`
Throws:
  `Exception`
Since:
  2.3

#### serializeAsPlaceholder

    public void serializeAsPlaceholder(Object bean,
                              JsonGenerator jgen,
                              SerializerProvider prov)
                                throws Exception

Method called to serialize a placeholder used in tabular output when real value is not to be included (is filtered out), but when we need an entry so that field indexes will not be off. Typically this should output null or empty String, depending on datatype.

Specified by:
  `serializeAsPlaceholder` in class `PropertyWriter`
Throws:
  `Exception`
Since:
  2.1

#### depositSchemaProperty

    public void depositSchemaProperty(JsonObjectFormatVisitor v)
                               throws JsonMappingException

Description copied from class: `PropertyWriter`
Traversal method used for things like JSON Schema generation, or POJO introspection.

Specified by:
  `depositSchemaProperty` in interface `BeanProperty`
Specified by:
  `depositSchemaProperty` in class `PropertyWriter`
Parameters:
  `v` - Visitor to used as the callback handler
Throws:
  `JsonMappingException`

#### depositSchemaProperty

    @Deprecated
    public void depositSchemaProperty(ObjectNode propertiesNode,
                                        SerializerProvider provider)
                               throws JsonMappingException

Deprecated.
Attempt to add the output of the given `BeanPropertyWriter` in the given `ObjectNode`. Otherwise, add the default schema `JsonNode` in place of the writer's output

Specified by:
  `depositSchemaProperty` in class `PropertyWriter`
Parameters:
  `propertiesNode` - Node which the given property would exist within
  `provider` - Provider that can be used for accessing dynamic aspects of serialization processing
Throws:
  `JsonMappingException`

#### _findAndAddDynamic

    protected JsonSerializer<Object> _findAndAddDynamic(PropertySerializerMap map,
                                            Class<?> type,
                                            SerializerProvider provider)
                                                 throws JsonMappingException

Throws:
  `JsonMappingException`

#### get

    public final Object get(Object bean)
                     throws Exception

Method that can be used to access value of the property this Object describes, from given bean instance.

Note: method is final as it should not need to be overridden -- rather, calling method(s) (`serializeAsField(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider)`) should be overridden to change the behavior

Throws:
  `Exception`

#### _handleSelfReference

    @Deprecated
    protected void _handleSelfReference(Object bean,
                                       JsonSerializer<?> ser)
                                 throws JsonMappingException

Deprecated. Since 2.3 Use overloaded variants

Throws:
  `JsonMappingException`

#### _handleSelfReference

    protected boolean _handleSelfReference(Object bean,
                               JsonGenerator jgen,
                               SerializerProvider prov,
                               JsonSerializer<?> ser)
                                    throws JsonMappingException

Method called to handle a direct self-reference through this property. Method can choose to indicate an error by throwing `JsonMappingException`; fully handle serialization (and return true); or indicate that it should be serialized normally (return false).

Default implementation will throw `JsonMappingException` if `SerializationFeature.FAIL_ON_SELF_REFERENCES` is enabled; or return `false` if it is disabled.

Returns:
  True if method fully handled self-referential value; false if not (caller is to handle it) or `JsonMappingException` if there is no way handle it
Throws:
  `JsonMappingException`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`