org.codehaus.jackson.map.ser
Class BeanPropertyWriter

java.lang.Object
  extended by org.codehaus.jackson.map.ser.BeanPropertyWriter

public class BeanPropertyWriter
extends Object

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


Field Summary
protected  Method _accessorMethod
          Accessor method used to get property value, for method-accessible properties.
protected  Class<?> _cfgSerializationType
          Type to use for locating serializer; normally same as return type of the accessor method, but may be overridden by annotations.
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  String _name
          Logical name of the property; will be used as the field name under which value for the property is written.
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
           
protected  boolean _suppressNulls
          Flag to indicate that null values for this property are not to be written out.
 
Constructor Summary
protected BeanPropertyWriter(BeanPropertyWriter base)
          "Copy constructor" to be used by filtering sub-classes
  BeanPropertyWriter(String name, JsonSerializer<Object> ser, Class<?> serType, Method acc, Field f, boolean suppressNulls, Object suppressableValue)
           
 
Method Summary
protected  void _reportSelfReference(Object bean)
           
 Object get(Object bean)
          Method that can be used to access value of the property this Object describes, from given bean instance.
 Type getGenericPropertyType()
          Get the generic property type of this property writer.
 String getName()
           
 Class<?> getReturnType()
           
 Class<?> getSerializationType()
           
protected  JsonSerializer<Object> getSerializer()
           
 Class<?>[] getViews()
           
 boolean hasSerializer()
           
 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 setViews(Class<?>[] views)
          Method for defining which views to included value of this property in.
 String toString()
           
 BeanPropertyWriter withSerializer(JsonSerializer<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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

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


_name

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


_cfgSerializationType

protected final Class<?> _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<Object> _serializer
Serializer to use for writing out the value: null if it can not be known statically; non-null if it can.


_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 Object _suppressableValue

_includeInViews

protected Class<?>[] _includeInViews
Alternate set of property writers used when view-based filtering is available for the Bean.

Since:
1.4
Constructor Detail

BeanPropertyWriter

public BeanPropertyWriter(String name,
                          JsonSerializer<Object> ser,
                          Class<?> serType,
                          Method acc,
                          Field f,
                          boolean suppressNulls,
                          Object suppressableValue)
Parameters:
suppressableValue - Value to suppress

BeanPropertyWriter

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

Method Detail

withSerializer

public BeanPropertyWriter withSerializer(JsonSerializer<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).


setViews

public void setViews(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).


hasSerializer

public boolean hasSerializer()

getSerializer

protected JsonSerializer<Object> getSerializer()

getSerializationType

public Class<?> getSerializationType()

getReturnType

public Class<?> getReturnType()

getName

public final String getName()

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

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.

Throws:
Exception

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, org.codehaus.jackson.JsonGenerator, org.codehaus.jackson.map.SerializerProvider)) should be overridden to change the behavior

Throws:
Exception

toString

public String toString()
Overrides:
toString in class Object

_reportSelfReference

protected void _reportSelfReference(Object bean)
                             throws JsonMappingException
Throws:
JsonMappingException