Class BeanPropertyWriter
- java.lang.Object
 - 
- com.fasterxml.jackson.databind.introspect.ConcreteBeanPropertyBase
 - 
- com.fasterxml.jackson.databind.ser.PropertyWriter
 - 
- com.fasterxml.jackson.databind.ser.BeanPropertyWriter
 
 
 
 
- 
- All Implemented Interfaces:
 BeanProperty,Named,java.io.Serializable
- Direct Known Subclasses:
 UnwrappingBeanPropertyWriter,VirtualBeanPropertyWriter
public class BeanPropertyWriter extends PropertyWriter implements java.io.Serializable
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.
- See Also:
 - Serialized Form
 
 
- 
- 
Nested Class Summary
- 
Nested classes/interfaces inherited from interface com.fasterxml.jackson.databind.BeanProperty
BeanProperty.Bogus, BeanProperty.Std 
 - 
 
- 
Field Summary
Fields Modifier and Type Field Description static java.lang.ObjectMARKER_FOR_EMPTYMarker object used to indicate "do not serialize if empty"- 
Fields inherited from interface com.fasterxml.jackson.databind.BeanProperty
EMPTY_FORMAT, EMPTY_INCLUDE 
 - 
 
- 
Constructor Summary
Constructors Constructor Description BeanPropertyWriter(BeanPropertyDefinition propDef, AnnotatedMember member, Annotations contextAnnotations, JavaType declaredType, JsonSerializer<?> ser, TypeSerializer typeSer, JavaType serType, boolean suppressNulls, java.lang.Object suppressableValue)Deprecated.BeanPropertyWriter(BeanPropertyDefinition propDef, AnnotatedMember member, Annotations contextAnnotations, JavaType declaredType, JsonSerializer<?> ser, TypeSerializer typeSer, JavaType serType, boolean suppressNulls, java.lang.Object suppressableValue, java.lang.Class<?>[] includeInViews) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidassignNullSerializer(JsonSerializer<java.lang.Object> nullSer)Method called to assign null value serializer for propertyvoidassignSerializer(JsonSerializer<java.lang.Object> ser)Method called to assign value serializer for propertyvoidassignTypeSerializer(TypeSerializer typeSer)Method called to set, reset or clear the configured type serializer for property.voiddepositSchemaProperty(JsonObjectFormatVisitor v, SerializerProvider provider)Traversal method used for things like JSON Schema generation, or POJO introspection.voiddepositSchemaProperty(ObjectNode propertiesNode, SerializerProvider provider)Deprecated.voidfixAccess(SerializationConfig config)Method called to ensure that the mutator has proper access rights to be called, as per configuration.java.lang.Objectget(java.lang.Object bean)Method that can be used to access value of the property this Object describes, from given bean instance.<A extends java.lang.annotation.Annotation>
AgetAnnotation(java.lang.Class<A> acls)Method for accessing annotations directly declared for property that this writer is associated with.<A extends java.lang.annotation.Annotation>
AgetContextAnnotation(java.lang.Class<A> acls)Method for accessing annotations declared in context of the property that this writer is associated with; usually this means annotations on enclosing class for property.PropertyNamegetFullName()Method for getting full name definition, including possible format-specific additional properties (such as namespace when using XML backend).java.lang.reflect.TypegetGenericPropertyType()Deprecated.Since 2.7, to be removed from 2.9, usegetType()instead.java.lang.ObjectgetInternalSetting(java.lang.Object key)Method for accessing value of specified internal setting.AnnotatedMembergetMember()Method for accessing primary physical entity that represents the property; annotated field, method or constructor property.java.lang.StringgetName()Method to get logical name of the propertyjava.lang.Class<?>getPropertyType()Deprecated.Since 2.7, to be removed from 2.9, usegetType()instead.java.lang.Class<?>getRawSerializationType()Deprecated.JavaTypegetSerializationType()SerializableStringgetSerializedName()JsonSerializer<java.lang.Object>getSerializer()JavaTypegetType()Method to get declared type of the property.TypeSerializergetTypeSerializer()java.lang.Class<?>[]getViews()PropertyNamegetWrapperName()If property is indicated to be wrapped, name of wrapper element to use.booleanhasNullSerializer()booleanhasSerializer()booleanisUnwrapping()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).java.lang.ObjectremoveInternalSetting(java.lang.Object key)Method for removing entry for specified internal setting.BeanPropertyWriterrename(NameTransformer transformer)voidserializeAsElement(java.lang.Object bean, JsonGenerator gen, SerializerProvider prov)Alternative toserializeAsField(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.voidserializeAsField(java.lang.Object bean, JsonGenerator gen, 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.voidserializeAsOmittedField(java.lang.Object bean, JsonGenerator gen, 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.voidserializeAsPlaceholder(java.lang.Object bean, JsonGenerator gen, 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.java.lang.ObjectsetInternalSetting(java.lang.Object key, java.lang.Object value)Method for setting specific internal setting to given valuevoidsetNonTrivialBaseType(JavaType t)Method called to define type to consider as "non-trivial" basetype, needed for dynamic serialization resolution for complex (usually container) typesjava.lang.StringtoString()BeanPropertyWriterunwrappingWriter(NameTransformer unwrapper)Method called create an instance that handles details of unwrapping contained value.booleanwillSuppressNulls()booleanwouldConflictWithName(PropertyName name)Method called to check to see if this property has a name that would conflict with a given name.- 
Methods inherited from class com.fasterxml.jackson.databind.ser.PropertyWriter
findAnnotation 
- 
Methods inherited from class com.fasterxml.jackson.databind.introspect.ConcreteBeanPropertyBase
findAliases, findFormatOverrides, findPropertyFormat, findPropertyInclusion, getMetadata, isRequired, isVirtual 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
BeanPropertyWriter
public BeanPropertyWriter(BeanPropertyDefinition propDef, AnnotatedMember member, Annotations contextAnnotations, JavaType declaredType, JsonSerializer<?> ser, TypeSerializer typeSer, JavaType serType, boolean suppressNulls, java.lang.Object suppressableValue, java.lang.Class<?>[] includeInViews)
- Since:
 - 2.9 (added `includeInViews` since 2.8)
 
 
- 
BeanPropertyWriter
@Deprecated public BeanPropertyWriter(BeanPropertyDefinition propDef, AnnotatedMember member, Annotations contextAnnotations, JavaType declaredType, JsonSerializer<?> ser, TypeSerializer typeSer, JavaType serType, boolean suppressNulls, java.lang.Object suppressableValue)
Deprecated. 
 - 
 
- 
Method Detail
- 
rename
public BeanPropertyWriter rename(NameTransformer transformer)
 
- 
assignTypeSerializer
public void assignTypeSerializer(TypeSerializer typeSer)
Method called to set, reset or clear the configured type serializer for property.- Since:
 - 2.6
 
 
- 
assignSerializer
public void assignSerializer(JsonSerializer<java.lang.Object> ser)
Method called to assign value serializer for property 
- 
assignNullSerializer
public void assignNullSerializer(JsonSerializer<java.lang.Object> nullSer)
Method called to assign null value serializer for property 
- 
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 
- 
fixAccess
public void fixAccess(SerializationConfig config)
Method called to ensure that the mutator has proper access rights to be called, as per configuration. Overridden by implementations that have mutators that require access, fields and setters.- Since:
 - 2.8.3
 
 
- 
getName
public java.lang.String getName()
Description copied from interface:BeanPropertyMethod to get logical name of the property- Specified by:
 getNamein interfaceBeanProperty- Specified by:
 getNamein interfaceNamed- Specified by:
 getNamein classPropertyWriter
 
- 
getFullName
public PropertyName getFullName()
Description copied from interface:BeanPropertyMethod for getting full name definition, including possible format-specific additional properties (such as namespace when using XML backend).- Specified by:
 getFullNamein interfaceBeanProperty- Specified by:
 getFullNamein classPropertyWriter
 
- 
getType
public JavaType getType()
Description copied from interface:BeanPropertyMethod to get declared type of the property.- Specified by:
 getTypein interfaceBeanProperty
 
- 
getWrapperName
public PropertyName getWrapperName()
Description copied from interface:BeanPropertyIf property is indicated to be wrapped, name of wrapper element to use.- Specified by:
 getWrapperNamein interfaceBeanProperty
 
- 
getAnnotation
public <A extends java.lang.annotation.Annotation> A getAnnotation(java.lang.Class<A> acls)
Description copied from class:PropertyWriterMethod for accessing annotations directly declared for property that this writer is associated with.- Specified by:
 getAnnotationin interfaceBeanProperty- Specified by:
 getAnnotationin classPropertyWriter
 
- 
getContextAnnotation
public <A extends java.lang.annotation.Annotation> A getContextAnnotation(java.lang.Class<A> acls)
Description copied from class:PropertyWriterMethod for accessing annotations declared in context of the property that this writer is associated with; usually this means annotations on enclosing class for property.- Specified by:
 getContextAnnotationin interfaceBeanProperty- Specified by:
 getContextAnnotationin classPropertyWriter
 
- 
getMember
public AnnotatedMember getMember()
Description copied from interface:BeanPropertyMethod for accessing primary physical entity that represents the property; annotated field, method or constructor property.- Specified by:
 getMemberin interfaceBeanProperty
 
- 
getInternalSetting
public java.lang.Object getInternalSetting(java.lang.Object key)
Method for accessing value of specified internal setting.- Returns:
 - Value of the setting, if any; null if none.
 
 
- 
setInternalSetting
public java.lang.Object setInternalSetting(java.lang.Object key, java.lang.Object value)Method for setting specific internal setting to given value- Returns:
 - Old value of the setting, if any (null if none)
 
 
- 
removeInternalSetting
public java.lang.Object removeInternalSetting(java.lang.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()
 
- 
getTypeSerializer
public TypeSerializer getTypeSerializer()
- Since:
 - 2.6
 
 
- 
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()
 
- 
wouldConflictWithName
public boolean wouldConflictWithName(PropertyName name)
Method called to check to see if this property has a name that would conflict with a given name.- Since:
 - 2.6
 
 
- 
getSerializer
public JsonSerializer<java.lang.Object> getSerializer()
 
- 
getSerializationType
public JavaType getSerializationType()
 
- 
getRawSerializationType
@Deprecated public java.lang.Class<?> getRawSerializationType()
Deprecated. 
- 
getPropertyType
@Deprecated public java.lang.Class<?> getPropertyType()
Deprecated.Since 2.7, to be removed from 2.9, usegetType()instead. 
- 
getGenericPropertyType
@Deprecated public java.lang.reflect.Type getGenericPropertyType()
Deprecated.Since 2.7, to be removed from 2.9, usegetType()instead.Get the generic property type of this property writer.- Returns:
 - The property type, or null if not found.
 
 
- 
getViews
public java.lang.Class<?>[] getViews()
 
- 
serializeAsField
public void serializeAsField(java.lang.Object bean, JsonGenerator gen, SerializerProvider prov) throws java.lang.ExceptionMethod 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:
 serializeAsFieldin classPropertyWriter- Throws:
 java.lang.Exception
 
- 
serializeAsOmittedField
public void serializeAsOmittedField(java.lang.Object bean, JsonGenerator gen, SerializerProvider prov) throws java.lang.ExceptionMethod 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:
 serializeAsOmittedFieldin classPropertyWriter- Throws:
 java.lang.Exception- Since:
 - 2.3
 
 
- 
serializeAsElement
public void serializeAsElement(java.lang.Object bean, JsonGenerator gen, SerializerProvider prov) throws java.lang.ExceptionAlternative toserializeAsField(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:
 serializeAsElementin classPropertyWriter- Throws:
 java.lang.Exception- Since:
 - 2.3
 
 
- 
serializeAsPlaceholder
public void serializeAsPlaceholder(java.lang.Object bean, JsonGenerator gen, SerializerProvider prov) throws java.lang.ExceptionMethod 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:
 serializeAsPlaceholderin classPropertyWriter- Throws:
 java.lang.Exception- Since:
 - 2.1
 
 
- 
depositSchemaProperty
public void depositSchemaProperty(JsonObjectFormatVisitor v, SerializerProvider provider) throws JsonMappingException
Description copied from class:PropertyWriterTraversal method used for things like JSON Schema generation, or POJO introspection.- Specified by:
 depositSchemaPropertyin interfaceBeanProperty- Specified by:
 depositSchemaPropertyin classPropertyWriter- 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 givenBeanPropertyWriterin the givenObjectNode. Otherwise, add the default schemaJsonNodein place of the writer's output- Specified by:
 depositSchemaPropertyin classPropertyWriter- Parameters:
 propertiesNode- Node which the given property would exist withinprovider- Provider that can be used for accessing dynamic aspects of serialization processing- Throws:
 JsonMappingException
 
- 
get
public final java.lang.Object get(java.lang.Object bean) throws java.lang.ExceptionMethod 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:
 java.lang.Exception
 
- 
toString
public java.lang.String toString()
- Overrides:
 toStringin classjava.lang.Object
 
 - 
 
 -