Package org.codehaus.jackson.map.ser
Class BeanPropertyWriter
- java.lang.Object
-
- org.codehaus.jackson.map.ser.BeanPropertyWriter
-
- All Implemented Interfaces:
BeanProperty,Named
- Direct Known Subclasses:
UnwrappingBeanPropertyWriter
public class BeanPropertyWriter extends java.lang.Object implements BeanProperty
Base bean property handler class, which implements common parts of reflection-based functionality for accessing a property value and serializing it.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.codehaus.jackson.map.BeanProperty
BeanProperty.Std
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.reflect.Method_accessorMethodAccessor method used to get property value, for method-accessible properties.protected JavaType_cfgSerializationTypeType to use for locating serializer; normally same as return type of the accessor method, but may be overridden by annotations.protected Annotations_contextAnnotationsAnnotations from context (most often, class that declares property, or in case of sub-class serializer, from that sub-class)protected JavaType_declaredTypeType property is declared to have, either in class definition or associated annotations.protected PropertySerializerMap_dynamicSerializersIn case serializer is not known statically (i.e.protected java.lang.reflect.Field_fieldField that contains the property value for field-accessible properties.protected java.lang.Class<?>[]_includeInViewsAlternate set of property writers used when view-based filtering is available for the Bean.protected java.util.HashMap<java.lang.Object,java.lang.Object>_internalSettingsprotected AnnotatedMember_memberMember (field, method) that represents property and allows access to associated annotations.protected SerializedString_nameLogical name of the property; will be used as the field name under which value for the property is written.protected JavaType_nonTrivialBaseTypeBase type of the property, if the declared type is "non-trivial"; meaning it is either a structured type (collection, map, array), or parametrized.protected JsonSerializer<java.lang.Object>_serializerSerializer to use for writing out the value: null if it can not be known statically; non-null if it can.protected java.lang.Object_suppressableValueValue that is considered default value of the property; used for default-value-suppression if enabled.protected boolean_suppressNullsFlag to indicate that null values for this property are not to be written out.protected TypeSerializer_typeSerializerIf property being serialized needs type information to be included this is the type serializer to use.
-
Constructor Summary
Constructors Modifier Constructor Description BeanPropertyWriter(AnnotatedMember member, Annotations contextAnnotations, java.lang.String name, JavaType declaredType, JsonSerializer<java.lang.Object> ser, TypeSerializer typeSer, JavaType serType, java.lang.reflect.Method m, java.lang.reflect.Field f, boolean suppressNulls, java.lang.Object suppressableValue)BeanPropertyWriter(AnnotatedMember member, Annotations contextAnnotations, SerializedString name, JavaType declaredType, JsonSerializer<java.lang.Object> ser, TypeSerializer typeSer, JavaType serType, java.lang.reflect.Method m, java.lang.reflect.Field f, boolean suppressNulls, java.lang.Object suppressableValue)protectedBeanPropertyWriter(BeanPropertyWriter base)"Copy constructor" to be used by filtering sub-classesprotectedBeanPropertyWriter(BeanPropertyWriter base, JsonSerializer<java.lang.Object> ser)"Copy constructor" to be used by filtering sub-classes
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected JsonSerializer<java.lang.Object>_findAndAddDynamic(PropertySerializerMap map, java.lang.Class<?> type, SerializerProvider provider)protected void_reportSelfReference(java.lang.Object bean)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 finding annotation associated with this property; meaning annotation associated with one of entities used to access property.<A extends java.lang.annotation.Annotation>
AgetContextAnnotation(java.lang.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).java.lang.reflect.TypegetGenericPropertyType()Get the generic property type of this property writer.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()java.lang.Class<?>getRawSerializationType()JavaTypegetSerializationType()SerializedStringgetSerializedName()JsonSerializer<java.lang.Object>getSerializer()JavaTypegetType()Method to get declared type of the property.java.lang.Class<?>[]getViews()booleanhasSerializer()java.lang.ObjectremoveInternalSetting(java.lang.Object key)Method for removing entry for specified internal setting.voidserializeAsField(java.lang.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.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) typesvoidsetViews(java.lang.Class<?>[] views)Method for defining which views to included value of this property in.java.lang.StringtoString()BeanPropertyWriterunwrappingWriter()Method called create an instance that handles details of unwrapping contained value.BeanPropertyWriterwithSerializer(JsonSerializer<java.lang.Object> ser)Method that will construct and return a new writer that has same properties as this writer, but uses specified serializer instead of currently configured one (if any).
-
-
-
Field Detail
-
_member
protected final AnnotatedMember _member
Member (field, method) that represents property and allows access to associated annotations.- Since:
- 1.7
-
_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 java.lang.reflect.Method _accessorMethod
Accessor method used to get property value, for method-accessible properties. Null if and only if_fieldis null.
-
_field
protected final java.lang.reflect.Field _field
Field that contains the property value for field-accessible properties. Null if and only if_accessorMethodis null.
-
_internalSettings
protected java.util.HashMap<java.lang.Object,java.lang.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.
-
_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 final JsonSerializer<java.lang.Object> _serializer
Serializer to use for writing out the value: null if it can not be known statically; non-null if it can.
-
_dynamicSerializers
protected PropertySerializerMap _dynamicSerializers
In case serializer is not known statically (i.e._serializeris null), we will use a lookup structure for storing dynamically resolved mapping from type(s) to serializer(s).- Since:
- 1.7
-
_suppressNulls
protected final boolean _suppressNulls
Flag to indicate that null values for this property are not to be written out. That is, if property has value null, no entry will be written
-
_suppressableValue
protected final java.lang.Object _suppressableValue
Value that is considered default value of the property; used for default-value-suppression if enabled.
-
_includeInViews
protected java.lang.Class<?>[] _includeInViews
Alternate set of property writers used when view-based filtering is available for the Bean.- Since:
- 1.4
-
_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 parametrized. Used to retain type information about contained type, which is mostly necessary if type metadata is to be included.- Since:
- 1.5
-
-
Constructor Detail
-
BeanPropertyWriter
public BeanPropertyWriter(AnnotatedMember member, Annotations contextAnnotations, java.lang.String name, JavaType declaredType, JsonSerializer<java.lang.Object> ser, TypeSerializer typeSer, JavaType serType, java.lang.reflect.Method m, java.lang.reflect.Field f, boolean suppressNulls, java.lang.Object suppressableValue)
-
BeanPropertyWriter
public BeanPropertyWriter(AnnotatedMember member, Annotations contextAnnotations, SerializedString name, JavaType declaredType, JsonSerializer<java.lang.Object> ser, TypeSerializer typeSer, JavaType serType, java.lang.reflect.Method m, java.lang.reflect.Field f, boolean suppressNulls, java.lang.Object suppressableValue)
-
BeanPropertyWriter
protected BeanPropertyWriter(BeanPropertyWriter base)
"Copy constructor" to be used by filtering sub-classes
-
BeanPropertyWriter
protected BeanPropertyWriter(BeanPropertyWriter base, JsonSerializer<java.lang.Object> ser)
"Copy constructor" to be used by filtering sub-classes
-
-
Method Detail
-
withSerializer
public BeanPropertyWriter withSerializer(JsonSerializer<java.lang.Object> ser)
Method that will construct and return a new writer that has same properties as this writer, but uses specified serializer instead of currently configured one (if any).
-
unwrappingWriter
public BeanPropertyWriter unwrappingWriter()
Method called create an instance that handles details of unwrapping contained value.- Since:
- 1.9
-
setViews
public void setViews(java.lang.Class<?>[] views)
Method for defining which views to included value of this property in. If left undefined, will always be included; otherwise active view definition will be checked against definition list and value is only included if active view is one of defined views, or its sub-view (as defined by class/sub-class relationship).
-
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- Since:
- 1.5
-
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
-
getType
public JavaType getType()
Description copied from interface:BeanPropertyMethod to get declared type of the property.- Specified by:
getTypein interfaceBeanProperty
-
getAnnotation
public <A extends java.lang.annotation.Annotation> A getAnnotation(java.lang.Class<A> acls)
Description copied from interface:BeanPropertyMethod for finding annotation associated with this property; meaning annotation associated with one of entities used to access property.- Specified by:
getAnnotationin interfaceBeanProperty
-
getContextAnnotation
public <A extends java.lang.annotation.Annotation> A getContextAnnotation(java.lang.Class<A> acls)
Description copied from interface:BeanPropertyMethod for finding annotation associated with context of this property; usually class in which member is declared (or its subtype if processing subtype).- Specified by:
getContextAnnotationin interfaceBeanProperty
-
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.
- Since:
- 1.7
-
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)
- Since:
- 1.7
-
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)
- Since:
- 1.7
-
getSerializedName
public SerializedString getSerializedName()
-
hasSerializer
public boolean hasSerializer()
-
getSerializer
public JsonSerializer<java.lang.Object> getSerializer()
-
getSerializationType
public JavaType getSerializationType()
-
getRawSerializationType
public java.lang.Class<?> getRawSerializationType()
-
getPropertyType
public java.lang.Class<?> getPropertyType()
-
getGenericPropertyType
public java.lang.reflect.Type getGenericPropertyType()
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 jgen, 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.- Throws:
java.lang.Exception
-
_findAndAddDynamic
protected JsonSerializer<java.lang.Object> _findAndAddDynamic(PropertySerializerMap map, java.lang.Class<?> type, SerializerProvider provider) throws JsonMappingException
- Throws:
JsonMappingException- Since:
- 1.7
-
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, org.codehaus.jackson.JsonGenerator, org.codehaus.jackson.map.SerializerProvider)) should be overridden to change the behavior- Throws:
java.lang.Exception
-
_reportSelfReference
protected void _reportSelfReference(java.lang.Object bean) throws JsonMappingException- Throws:
JsonMappingException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-