|
||||||||||
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
public class BeanSerializerFactory
Factory class that can provide serializers for any regular Java beans
(as defined by "having at least one get method recognizable as bean
accessor" -- where Object.getClass()
does not count);
as well as for "standard" JDK types. Latter is achieved
by delegating calls to BasicSerializerFactory
to find serializers both for "standard" JDK types (and in some cases,
sub-classes as is the case for collection classes like
List
s and Map
s) and bean (value)
classes.
Note about delegating calls to BasicSerializerFactory
:
although it would be nicer to use linear delegation
for construction (to essentially dispatch all calls first to the
underlying BasicSerializerFactory
; or alternatively after
failing to provide bean-based serializer}, there is a problem:
priority levels for detecting standard types are mixed. That is,
we want to check if a type is a bean after some of "standard" JDK
types, but before the rest.
As a result, "mixed" delegation used, and calls are NOT done using
regular SerializerFactory
interface but rather via
direct calls to BasicSerializerFactory
.
Finally, since all caching is handled by the serializer provider (not factory) and there is no configurability, this factory is stateless. This means that a global singleton instance can be used.
Nested Class Summary |
---|
Field Summary | |
---|---|
static BeanSerializerFactory |
instance
Like BasicSerializerFactory , this factory is stateless, and
thus a single shared global (== singleton) instance can be used
without thread-safety issues. |
Constructor Summary | |
---|---|
protected |
BeanSerializerFactory()
We will provide default constructor to allow sub-classing, but make it protected so that no non-singleton instances of the class will be instantiated. |
Method Summary | ||
---|---|---|
protected JsonSerializer<Object> |
constructBeanSerializer(SerializationConfig config,
BasicBeanDescription beanDesc)
|
|
protected BeanPropertyWriter |
constructFilteredBeanWriter(BeanPropertyWriter writer,
Class<?>[] inViews)
Method called to construct a filtered writer, for given view definitions. |
|
protected PropertyBuilder |
constructPropertyBuilder(SerializationConfig config,
BasicBeanDescription beanDesc)
|
|
|
createSerializer(Class<T> type,
SerializationConfig config)
Main serializer constructor method. |
|
protected List<BeanPropertyWriter> |
filterBeanProperties(SerializationConfig config,
BasicBeanDescription beanDesc,
List<BeanPropertyWriter> props)
Overridable method that can filter out properties. |
|
protected List<BeanPropertyWriter> |
findBeanProperties(SerializationConfig config,
BasicBeanDescription beanDesc)
Method used to collect all actual serializable properties. |
|
JsonSerializer<Object> |
findBeanSerializer(Class<?> type,
SerializationConfig config)
Method that will try to construct a BeanSerializer for
given class. |
|
protected boolean |
isPotentialBeanType(Class<?> type)
Helper method used to skip processing for types that we know can not be (i.e. |
|
protected BeanSerializer |
processViews(SerializationConfig config,
BasicBeanDescription beanDesc,
BeanSerializer ser,
List<BeanPropertyWriter> props)
Method called to handle view information for constructed serializer, based on bean property writers. |
|
protected List<BeanPropertyWriter> |
sortBeanProperties(SerializationConfig config,
BasicBeanDescription beanDesc,
List<BeanPropertyWriter> props)
Overridable method that will impose given partial ordering on list of discovered propertied. |
|
protected boolean |
usesStaticTyping(SerializationConfig config,
BasicBeanDescription beanDesc)
Helper method to check whether global settings and/or class annotations for the bean class indicate that static typing (declared types) should be used for properties. |
Methods inherited from class org.codehaus.jackson.map.ser.BasicSerializerFactory |
---|
buildMapSerializer, findSerializerByAddonType, findSerializerByLookup, findSerializerByPrimaryType, findSerializerFromAnnotation, getNullSerializer |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final BeanSerializerFactory instance
BasicSerializerFactory
, this factory is stateless, and
thus a single shared global (== singleton) instance can be used
without thread-safety issues.
Constructor Detail |
---|
protected BeanSerializerFactory()
Method Detail |
---|
public <T> JsonSerializer<T> createSerializer(Class<T> type, SerializationConfig config)
Iterable
.
Note: sub-classes may choose to complete replace implementation, if they want to alter priority of serializer lookups.
createSerializer
in class BasicSerializerFactory
type
- Type to be serializedconfig
- Generic serialization configurationpublic JsonSerializer<Object> findBeanSerializer(Class<?> type, SerializationConfig config)
BeanSerializer
for
given class. Returns null if no properties are found.
protected boolean isPotentialBeanType(Class<?> type)
Note that usually we shouldn't really be getting these sort of types anyway; but better safe than sorry.
protected JsonSerializer<Object> constructBeanSerializer(SerializationConfig config, BasicBeanDescription beanDesc)
protected List<BeanPropertyWriter> findBeanProperties(SerializationConfig config, BasicBeanDescription beanDesc)
protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig config, BasicBeanDescription beanDesc, List<BeanPropertyWriter> props)
protected List<BeanPropertyWriter> sortBeanProperties(SerializationConfig config, BasicBeanDescription beanDesc, List<BeanPropertyWriter> props)
By default Creator properties will be ordered before other properties. Explicit custom ordering will override this implicit default ordering.
protected BeanSerializer processViews(SerializationConfig config, BasicBeanDescription beanDesc, BeanSerializer ser, List<BeanPropertyWriter> props)
Note that this method is designed to be overridden by sub-classes if they want to provide custom view handling. As such it is not considered an internal implementation detail, and will be supported as part of API going forward.
protected BeanPropertyWriter constructFilteredBeanWriter(BeanPropertyWriter writer, Class<?>[] inViews)
protected PropertyBuilder constructPropertyBuilder(SerializationConfig config, BasicBeanDescription beanDesc)
protected boolean usesStaticTyping(SerializationConfig config, BasicBeanDescription beanDesc)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |