|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.jackson.map.JsonSerializer<T>
org.codehaus.jackson.map.ser.SerializerBase<Object>
org.codehaus.jackson.map.ser.BeanSerializer
public class BeanSerializer
Serializer class that can serialize arbitrary bean objects
Implementation note: we will post-process resulting serializer,
to figure out actual serializers for final types. This must be
done from resolve(org.codehaus.jackson.map.SerializerProvider)
method, and NOT from constructor;
otherwise we could end up with an infinite loop.
Since 1.7 instances are immutable; this is achieved by using a separate builder during construction process.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.codehaus.jackson.map.JsonSerializer |
---|
JsonSerializer.None |
Field Summary | |
---|---|
protected AnyGetterWriter |
_anyGetterWriter
Handler for JsonAnyGetter
annotated properties |
protected BeanPropertyWriter[] |
_filteredProps
Optional filters used to suppress output of properties that are only to be included in certain views |
protected Object |
_propertyFilterId
Id of the bean property filter to use, if any; null if none. |
protected BeanPropertyWriter[] |
_props
Writers used for outputting actual property values |
protected static BeanPropertyWriter[] |
NO_PROPS
|
Fields inherited from class org.codehaus.jackson.map.ser.SerializerBase |
---|
_handledType |
Constructor Summary | |
---|---|
protected |
BeanSerializer(BeanSerializer src)
Copy-constructor that is useful for sub-classes that just want to copy all super-class properties without modifications. |
|
BeanSerializer(Class<?> rawType,
BeanPropertyWriter[] properties,
BeanPropertyWriter[] filteredProperties,
AnyGetterWriter anyGetterWriter,
Object filterId)
|
|
BeanSerializer(JavaType type,
BeanPropertyWriter[] properties,
BeanPropertyWriter[] filteredProperties,
AnyGetterWriter anyGetterWriter,
Object filterId)
|
Method Summary | |
---|---|
static BeanSerializer |
createDummy(Class<?> forType)
Method for constructing dummy bean deserializer; one that never outputs any properties |
protected BeanPropertyFilter |
findFilter(SerializerProvider provider)
Helper method used to locate filter that is needed, based on filter id this serializer was constructed with. |
JsonNode |
getSchema(SerializerProvider provider,
Type typeHint)
Get the representation of the schema to which this serializer will conform. |
void |
resolve(SerializerProvider provider)
Method called after SerializerProvider has registered
the serializer, but before it has returned it to the caller. |
void |
serialize(Object bean,
JsonGenerator jgen,
SerializerProvider provider)
Main serialization method that will delegate actual output to configured BeanPropertyWriter instances. |
protected void |
serializeFields(Object bean,
JsonGenerator jgen,
SerializerProvider provider)
|
protected void |
serializeFieldsFiltered(Object bean,
JsonGenerator jgen,
SerializerProvider provider)
Alternative serialization method that gets called when there is a BeanPropertyFilter that needs to be called to determine
which properties are to be serialized (and possibly how) |
void |
serializeWithType(Object bean,
JsonGenerator jgen,
SerializerProvider provider,
TypeSerializer typeSer)
Method that can be called to ask implementation to serialize values of type this serializer handles, using specified type serializer for embedding necessary type information. |
String |
toString()
|
Methods inherited from class org.codehaus.jackson.map.ser.SerializerBase |
---|
createObjectNode, createSchemaNode, createSchemaNode, handledType, isDefaultSerializer, wrapAndThrow, wrapAndThrow, wrapAndThrow, wrapAndThrow |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final BeanPropertyWriter[] NO_PROPS
protected final BeanPropertyWriter[] _props
protected final BeanPropertyWriter[] _filteredProps
protected final AnyGetterWriter _anyGetterWriter
JsonAnyGetter
annotated properties
protected final Object _propertyFilterId
Constructor Detail |
---|
public BeanSerializer(JavaType type, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties, AnyGetterWriter anyGetterWriter, Object filterId)
type
- Nominal type of values handled by this serializerproperties
- Property writers used for actual serializationpublic BeanSerializer(Class<?> rawType, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties, AnyGetterWriter anyGetterWriter, Object filterId)
protected BeanSerializer(BeanSerializer src)
Method Detail |
---|
public static BeanSerializer createDummy(Class<?> forType)
public final void serialize(Object bean, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException
BeanPropertyWriter
instances.
serialize
in class SerializerBase<Object>
bean
- Value to serialize; can not be null.jgen
- Generator used to output resulting Json contentprovider
- Provider that can be used to get serializers for
serializing Objects value contains, if any.
IOException
JsonGenerationException
public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonGenerationException
JsonSerializer
Default implementation will ignore serialization of type information,
and just calls JsonSerializer.serialize(T, org.codehaus.jackson.JsonGenerator, org.codehaus.jackson.map.SerializerProvider)
: serializers that can embed
type information should override this to implement actual handling.
Most common such handling is done by something like:
// note: method to call depends on whether this type is serialized as JSON scalar, object or Array! typeSer.writeTypePrefixForScalar(value, jgen); serialize(value, jgen, provider); typeSer.writeTypeSuffixForScalar(value, jgen);
serializeWithType
in class JsonSerializer<Object>
bean
- Value to serialize; can not be null.jgen
- Generator used to output resulting Json contentprovider
- Provider that can be used to get serializers for
serializing Objects value contains, if any.typeSer
- Type serializer to use for including type information
IOException
JsonGenerationException
protected void serializeFields(Object bean, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException
IOException
JsonGenerationException
protected void serializeFieldsFiltered(Object bean, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException
BeanPropertyFilter
that needs to be called to determine
which properties are to be serialized (and possibly how)
IOException
JsonGenerationException
protected BeanPropertyFilter findFilter(SerializerProvider provider) throws JsonMappingException
JsonMappingException
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException
SchemaAware
getSchema
in interface SchemaAware
getSchema
in class SerializerBase<Object>
provider
- The serializer provider.typeHint
- A hint about the type.
JsonMappingException
public void resolve(SerializerProvider provider) throws JsonMappingException
ResolvableSerializer
SerializerProvider
has registered
the serializer, but before it has returned it to the caller.
Called object can then resolve its dependencies to other types,
including self-references (direct or indirect).
resolve
in interface ResolvableSerializer
provider
- Provider that has constructed serializer this method
is called on.
JsonMappingException
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |