|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.jackson.map.SerializerFactory
org.codehaus.jackson.map.ser.BasicSerializerFactory
org.codehaus.jackson.map.ser.BeanSerializerFactory
org.codehaus.jackson.map.ser.CustomSerializerFactory
public class CustomSerializerFactory
Serializer factory implementation that allows for configuring
mapping between types (classes) and serializers to use, by using
multiple types of overrides. Existing mappings established by
BeanSerializerFactory
(and its super class,
BasicSerializerFactory
) are used if no overrides are
defined.
Unlike base serializer factories (BasicSerializerFactory
,
BeanSerializerFactory
), this factory is stateful because
of configuration settings. It is thread-safe, however, as long as
all configuration as done before using the factory -- a single
instance can be shared between providers and mappers.
Configurations currently available are:
In near future, following features are planned to be added:
Field Summary |
---|
Fields inherited from class org.codehaus.jackson.map.ser.BeanSerializerFactory |
---|
instance |
Constructor Summary | |
---|---|
CustomSerializerFactory()
|
Method Summary | ||
---|---|---|
|
addGenericMapping(Class<? extends T> type,
JsonSerializer<T> ser)
Method used to add a generic (transitive) mapping from specified class or its sub-classes into a serializer. |
|
|
addSpecificMapping(Class<? extends T> forClass,
JsonSerializer<T> ser)
Method used to add a mapping from specific type -- and only that type -- to specified serializer. |
|
|
createSerializer(Class<T> type,
SerializationConfig config)
Main serializer constructor method. |
|
JsonSerializer<Object> |
createSerializer(JavaType type,
SerializationConfig config)
Main serializer constructor method. |
|
protected JsonSerializer<?> |
findCustomSerializer(Class<?> type,
SerializationConfig config)
|
|
void |
setEnumSerializer(JsonSerializer<?> enumSer)
Method that can be used to force specified serializer to be used for serializing all Enum instances. |
Methods inherited from class org.codehaus.jackson.map.ser.BeanSerializerFactory |
---|
_constructWriter, constructBeanSerializer, constructFilteredBeanWriter, constructPropertyBuilder, filterBeanProperties, findBeanProperties, findBeanSerializer, findPropertyContentTypeSerializer, findPropertyTypeSerializer, isPotentialBeanType, processViews, sortBeanProperties |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CustomSerializerFactory()
Method Detail |
---|
public <T> void addGenericMapping(Class<? extends T> type, JsonSerializer<T> ser)
Class.getInterfaces()
), then super-type's and so forth.
Note that adding generic mappings may lead to problems with sub-classing: if sub-classes add new properties, these may not get properly serialized.
type
- Class for which specified serializer is to be
used. May be more specific type than what serializer indicates,
but must be compatible (same or sub-class)public <T> void addSpecificMapping(Class<? extends T> forClass, JsonSerializer<T> ser)
IllegalArgumentException
will be thrown to
indicate caller error.
forClass
- Class for which specified serializer is to be
used. May be more specific type than what serializer indicates,
but must be compatible (same or sub-class)public void setEnumSerializer(JsonSerializer<?> enumSer)
enum.toString()
, or modify
value returned by enum.name()
(such as upper- or
lower-casing it).
Note: this serializer has lower precedence than that of specific types; so if a specific serializer is assigned to an Enum type, this serializer will NOT be used. It has higher precedence than generic mappings have however.
public <T> JsonSerializer<T> createSerializer(Class<T> type, SerializationConfig config)
BasicSerializerFactory
createSerializer
in class BasicSerializerFactory
type
- Type to be serializedconfig
- Generic serialization configurationpublic JsonSerializer<Object> createSerializer(JavaType type, SerializationConfig config)
BeanSerializerFactory
Iterable
.
Note: sub-classes may choose to complete replace implementation, if they want to alter priority of serializer lookups.
createSerializer
in class BeanSerializerFactory
type
- Type to be serializedconfig
- Generic serialization configurationprotected JsonSerializer<?> findCustomSerializer(Class<?> type, SerializationConfig config)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |