- All Implemented Interfaces:
Serializable
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.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BeanSerializerFactoryLikeBasicSerializerFactory, this factory is stateless, and thus a single shared global (== singleton) instance can be used without thread-safety issues.Fields inherited from class tools.jackson.databind.ser.BasicSerializerFactory
_factoryConfig -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor for creating instances with specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected BeanPropertyWriter_constructWriter(SerializationContext ctxt, BeanPropertyDefinition propDef, PropertyBuilder pb, boolean staticTyping, AnnotatedMember accessor) Secondary helper method for constructingBeanPropertyWriterfor given member (field or method).protected ValueSerializer<?>_createSerializer2(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, JavaType type, JsonFormat.Value formatOverrides, boolean staticTyping) protected ValueSerializer<?>_findUnsupportedTypeSerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef) protected boolean_isUnserializableJacksonType(SerializationContext ctxt, JavaType type) protected ValueSerializer<Object>constructBeanOrAddOnSerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value format, boolean staticTyping) Method called to construct serializer based on checking which condition is matched: Nominal type isjava.lang.Object: if so, return special "no type known" serializer If a known "not-POJO" type (like JDKProxy), returnnullIf at least one logical property found, build actualBeanSerializerIf add-on type (likeIterable) found, create appropriate serializer If one of Jackson's "well-known" annotations found, create bogus "empty Object" Serializer or, if none matched, returnnull.protected BeanSerializerBuilderconstructBeanSerializerBuilder(SerializationConfig config, BeanDescription.Supplier beanDescRef) protected BeanPropertyWriterconstructFilteredBeanWriter(BeanPropertyWriter writer, Class<?>[] inViews) Method called to construct a filtered writer, for given view definitions.protected ObjectIdWriterconstructObjectIdHandler(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, List<BeanPropertyWriter> props) protected PropertyBuilderconstructPropertyBuilder(SerializationConfig config, BeanDescription.Supplier beanDescRef) createSerializer(SerializationContext ctxt, JavaType origType, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides) Main serializer constructor method.protected List<BeanPropertyWriter>filterBeanProperties(SerializationConfig config, BeanDescription.Supplier beanDescRef, List<BeanPropertyWriter> props) Overridable method that can filter out properties.protected List<BeanPropertyWriter>filterUnwantedJDKProperties(SerializationConfig config, BeanDescription.Supplier beanDescRef, List<BeanPropertyWriter> props) Overridable method used to filter out specifically problematic JDK provided properties.protected List<BeanPropertyWriter>findBeanProperties(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, BeanSerializerBuilder builder) Method used to collect all actual serializable properties.protected booleanisPotentialBeanType(Class<?> type) Helper method used to skip processing for types that we know cannot be (i.e. are never consider to be) beans: things like primitives, Arrays, Enums, and proxy types.protected voidprocessViews(SerializationConfig config, BeanSerializerBuilder builder) Method called to handle view information for constructed serializer, based on bean property writers.protected voidremoveIgnorableTypes(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, List<BeanPropertyDefinition> properties) Method that will apply by-type limitations (as per [JACKSON-429]); by default this is based onJsonIgnoreTypeannotation but can be supplied by module-provided introspectors too.protected List<BeanPropertyWriter>removeOverlappingTypeIds(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, BeanSerializerBuilder builder, List<BeanPropertyWriter> props) Helper method called to ensure that we do not have "duplicate" type ids.protected voidremoveSetterlessGetters(SerializationConfig config, BeanDescription.Supplier beanDescRef, List<BeanPropertyDefinition> properties) Helper method that will remove all properties that do not have a mutator.withConfig(SerializerFactoryConfig config) Method used by module registration functionality, to attach additional serializer providers into this serializer factory.Methods inherited from class tools.jackson.databind.ser.BasicSerializerFactory
_buildReferenceSerializer, _calculateEffectiveFormat, _checkMapContentInclusion, _findContentSerializer, _findInclusionWithContent, _findKeySerializer, buildArraySerializer, buildCollectionSerializer, buildCollectionSerializer, buildContainerSerializer, buildEnumSerializer, buildEnumSetSerializer, buildIndexedListSerializer, buildIterableSerializer, buildIteratorSerializer, buildMapEntrySerializer, buildMapSerializer, createKeySerializer, customSerializers, findConverter, findConvertingSerializer, findFilterId, findPropertyContentTypeSerializer, findReferenceSerializer, findSerializerByAddonType, findSerializerByAnnotations, findSerializerByPrimaryType, findSerializerFromAnnotation, getDefaultNullKeySerializer, getDefaultNullValueSerializer, isIndexedList, usesStaticTyping, withAdditionalKeySerializers, withAdditionalSerializers, withNullKeySerializer, withNullValueSerializer, withSerializerModifierMethods inherited from class tools.jackson.databind.ser.SerializerFactory
createSerializer
-
Field Details
-
instance
LikeBasicSerializerFactory, this factory is stateless, and thus a single shared global (== singleton) instance can be used without thread-safety issues.
-
-
Constructor Details
-
BeanSerializerFactory
Constructor for creating instances with specified configuration.
-
-
Method Details
-
withConfig
Method used by module registration functionality, to attach additional serializer providers into this serializer factory. This is typically handled by constructing a new instance with additional serializers, to ensure thread-safe access.- Specified by:
withConfigin classBasicSerializerFactory
-
createSerializer
public ValueSerializer<Object> createSerializer(SerializationContext ctxt, JavaType origType, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides) Main serializer constructor method. We will have to be careful with respect to ordering of various method calls: essentially we want to reliably figure out which classes are standard types, and which are beans. The problem is that some bean Classes may implement standard interfaces (say,Iterable.Note: sub-classes may choose to complete replace implementation, if they want to alter priority of serializer lookups.
- Specified by:
createSerializerin classSerializerFactory- Parameters:
ctxt- (not null) Context that needs to be used to resolve annotation-provided serializers (but NOT for others)formatOverrides- (nullable) Possible format overrides (from property annotations) to use, above and beyond what `beanDesc` defines
-
_createSerializer2
protected ValueSerializer<?> _createSerializer2(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, JavaType type, JsonFormat.Value formatOverrides, boolean staticTyping) -
constructBeanOrAddOnSerializer
protected ValueSerializer<Object> constructBeanOrAddOnSerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value format, boolean staticTyping) Method called to construct serializer based on checking which condition is matched:- Nominal type is
java.lang.Object: if so, return special "no type known" serializer - If a known "not-POJO" type (like JDK
Proxy), returnnull - If at least one logical property found, build actual
BeanSerializer - If add-on type (like
Iterable) found, create appropriate serializer - If one of Jackson's "well-known" annotations found, create bogus "empty Object" Serializer
null. - Nominal type is
-
constructObjectIdHandler
protected ObjectIdWriter constructObjectIdHandler(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, List<BeanPropertyWriter> props) -
constructFilteredBeanWriter
protected BeanPropertyWriter constructFilteredBeanWriter(BeanPropertyWriter writer, Class<?>[] inViews) Method called to construct a filtered writer, for given view definitions. Default implementation constructs filter that checks active view type to views property is to be included in. -
constructPropertyBuilder
protected PropertyBuilder constructPropertyBuilder(SerializationConfig config, BeanDescription.Supplier beanDescRef) -
constructBeanSerializerBuilder
protected BeanSerializerBuilder constructBeanSerializerBuilder(SerializationConfig config, BeanDescription.Supplier beanDescRef) -
isPotentialBeanType
Helper method used to skip processing for types that we know cannot be (i.e. are never consider to be) beans: things like primitives, Arrays, Enums, and proxy types.Note that usually we shouldn't really be getting these sort of types anyway; but better safe than sorry.
-
findBeanProperties
protected List<BeanPropertyWriter> findBeanProperties(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, BeanSerializerBuilder builder) Method used to collect all actual serializable properties. Can be overridden to implement custom detection schemes. -
filterBeanProperties
protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig config, BeanDescription.Supplier beanDescRef, List<BeanPropertyWriter> props) Overridable method that can filter out properties. Default implementation checks annotations class may have. -
filterUnwantedJDKProperties
protected List<BeanPropertyWriter> filterUnwantedJDKProperties(SerializationConfig config, BeanDescription.Supplier beanDescRef, List<BeanPropertyWriter> props) Overridable method used to filter out specifically problematic JDK provided properties.See issue databind-3305 for details.
-
processViews
Method called to handle view information for constructed serializer, based on bean property writers.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.
-
removeIgnorableTypes
protected void removeIgnorableTypes(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, List<BeanPropertyDefinition> properties) Method that will apply by-type limitations (as per [JACKSON-429]); by default this is based onJsonIgnoreTypeannotation but can be supplied by module-provided introspectors too. Starting with 2.8 there are also "Config overrides" to consider. -
removeSetterlessGetters
protected void removeSetterlessGetters(SerializationConfig config, BeanDescription.Supplier beanDescRef, List<BeanPropertyDefinition> properties) Helper method that will remove all properties that do not have a mutator. -
removeOverlappingTypeIds
protected List<BeanPropertyWriter> removeOverlappingTypeIds(SerializationContext ctxt, BeanDescription.Supplier beanDescRef, BeanSerializerBuilder builder, List<BeanPropertyWriter> props) Helper method called to ensure that we do not have "duplicate" type ids. Added to resolve [databind#222] -
_constructWriter
protected BeanPropertyWriter _constructWriter(SerializationContext ctxt, BeanPropertyDefinition propDef, PropertyBuilder pb, boolean staticTyping, AnnotatedMember accessor) Secondary helper method for constructingBeanPropertyWriterfor given member (field or method). -
_findUnsupportedTypeSerializer
protected ValueSerializer<?> _findUnsupportedTypeSerializer(SerializationContext ctxt, JavaType type, BeanDescription.Supplier beanDescRef) -
_isUnserializableJacksonType
-