Class BeanSerializerFactory

  • Direct Known Subclasses:
    CustomSerializerFactory

    public class BeanSerializerFactory
    extends BasicSerializerFactory
    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 Lists and Maps) 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.

    Notes for version 1.7 (and above): the new module registration system required addition of withConfig(org.codehaus.jackson.map.SerializerFactory.Config), which has to be redefined by sub-classes so that they can work properly with pluggable additional serializer providing components.

    • Field Detail

      • instance

        public static final BeanSerializerFactory instance
        Like BasicSerializerFactory, this factory is stateless, and thus a single shared global (== singleton) instance can be used without thread-safety issues.
      • _factoryConfig

        protected final SerializerFactory.Config _factoryConfig
        Configuration settings for this factory; immutable instance (just like this factory), new version created via copy-constructor (fluent-style)
        Since:
        1.7
    • Constructor Detail

      • BeanSerializerFactory

        protected BeanSerializerFactory​(SerializerFactory.Config config)
        Constructor for creating instances with specified configuration.