Class 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
    • Field Detail

      • MARKER_FOR_EMPTY

        public static final java.lang.Object MARKER_FOR_EMPTY
        Marker object used to indicate "do not serialize if empty"
      • _name

        protected final com.fasterxml.jackson.core.io.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 (until 2.4; not directly from 2.5) 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
      • _declaredType

        protected final JavaType _declaredType
        Type property is declared to have, either in class definition or associated annotations.
      • _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.
      • _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.
      • _contextAnnotations

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

        NOTE: transient just to support JDK serializability; Annotations do not serialize. At all.

      • _member

        protected final AnnotatedMember _member
        Member (field, method) that represents property and allows access to associated annotations.
      • _accessorMethod

        protected transient java.lang.reflect.Method _accessorMethod
        Accessor method used to get property value, for method-accessible properties. Null if and only if _field is null.

        `transient` (and non-final) only to support JDK serializability.

      • _field

        protected transient java.lang.reflect.Field _field
        Field that contains the property value for field-accessible properties. Null if and only if _accessorMethod is null.

        `transient` (and non-final) only to support JDK serializability.

      • _serializer

        protected JsonSerializer<java.lang.Object> _serializer
        Serializer to use for writing out the value: null if it cannot be known statically; non-null if it can.
      • _nullSerializer

        protected JsonSerializer<java.lang.Object> _nullSerializer
        Serializer used for writing out null values, if any: if null, null values are to be suppressed.
      • _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).
      • _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. Note that this is a configuration value during construction, and actual handling relies on setting (or not) of _nullSerializer.
      • _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 final java.lang.Class<?>[] _includeInViews
        Alternate set of property writers used when view-based filtering is available for the Bean.
      • _internalSettings

        protected transient java.util.HashMap<java.lang.Object,​java.lang.Object> _internalSettings
    • Constructor Detail

      • BeanPropertyWriter

        protected BeanPropertyWriter()
        Constructor that may be of use to virtual properties, when there is need for the zero-arg ("default") constructor, and actual initialization is done after constructor call.
        Since:
        2.5
      • BeanPropertyWriter

        protected BeanPropertyWriter​(BeanPropertyWriter base)
        "Copy constructor" to be used by filtering sub-classes
      • BeanPropertyWriter

        protected BeanPropertyWriter​(BeanPropertyWriter base,
                                     com.fasterxml.jackson.core.io.SerializedString name)
    • Method Detail

      • 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
      • getAnnotation

        public <A extends java.lang.annotation.Annotation> A getAnnotation​(java.lang.Class<A> acls)
        Description copied from class: PropertyWriter
        Method for accessing annotations directly declared for property that this writer is associated with.
        Specified by:
        getAnnotation in interface BeanProperty
        Specified by:
        getAnnotation in class PropertyWriter
      • getContextAnnotation

        public <A extends java.lang.annotation.Annotation> A getContextAnnotation​(java.lang.Class<A> acls)
        Description copied from class: PropertyWriter
        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.
        Specified by:
        getContextAnnotation in interface BeanProperty
        Specified by:
        getContextAnnotation in class PropertyWriter
      • 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 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 com.fasterxml.jackson.core.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, use getType() instead.
      • getGenericPropertyType

        @Deprecated
        public java.lang.reflect.Type getGenericPropertyType()
        Deprecated.
        Since 2.7, to be removed from 2.9, use getType() 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,
                                     com.fasterxml.jackson.core.JsonGenerator gen,
                                     SerializerProvider prov)
                              throws java.lang.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:
        java.lang.Exception
      • serializeAsOmittedField

        public void serializeAsOmittedField​(java.lang.Object bean,
                                            com.fasterxml.jackson.core.JsonGenerator gen,
                                            SerializerProvider prov)
                                     throws java.lang.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:
        java.lang.Exception
        Since:
        2.3
      • serializeAsPlaceholder

        public void serializeAsPlaceholder​(java.lang.Object bean,
                                           com.fasterxml.jackson.core.JsonGenerator gen,
                                           SerializerProvider prov)
                                    throws java.lang.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:
        java.lang.Exception
        Since:
        2.1
      • _handleSelfReference

        protected boolean _handleSelfReference​(java.lang.Object bean,
                                               com.fasterxml.jackson.core.JsonGenerator gen,
                                               SerializerProvider prov,
                                               JsonSerializer<?> ser)
                                        throws java.io.IOException
        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:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object