java.lang.Object
tools.jackson.databind.ValueSerializer<T>
tools.jackson.databind.ser.std.StdSerializer<Object>
tools.jackson.databind.ser.bean.BeanSerializerBase
- All Implemented Interfaces:
JsonFormatVisitable
- Direct Known Subclasses:
BeanAsArraySerializer,BeanSerializer,UnrolledBeanAsArraySerializer,UnrolledBeanSerializer,UnwrappingBeanSerializer
Base class both for the standard bean serializer, and couple
of variants that only differ in small details.
Can be used for custom bean serializers as well, although that
is not the primary design goal.
-
Nested Class Summary
Nested classes/interfaces inherited from class tools.jackson.databind.ValueSerializer
ValueSerializer.None -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final JavaTypeprotected final BeanPropertyWriter[]Optional filters used to suppress output of properties that are only to be included in certain viewsprotected final ObjectIdWriterIf this POJO can be alternatively serialized using just an object id to denote a reference to previously serialized object, this Object will handle details.protected final ObjectId of the bean property filter to use, if any; null if none.protected final BeanPropertyWriter[]Writers used for outputting actual property valuesprotected final JsonFormat.ShapeRequested shape from bean class annotations.protected final AnnotatedMemberIf using custom type ids (usually via getter, or field), this is the reference to that member.protected static final PropertyNameprotected static final BeanPropertyWriter[]Fields inherited from class tools.jackson.databind.ser.std.StdSerializer
_handledType -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBeanSerializerBase(JavaType type, BeanSerializerBuilder builder, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties) Constructor used byBeanSerializerBuilderto create an instanceprotectedCopy-constructor that is useful for sub-classes that just want to copy all super-class properties without modifications.protectedBeanSerializerBase(BeanSerializerBase src, Set<String> toIgnore, Set<String> toInclude) protectedBeanSerializerBase(BeanSerializerBase src, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties) protectedBeanSerializerBase(BeanSerializerBase src, ObjectIdWriter objectIdWriter) protectedBeanSerializerBase(BeanSerializerBase src, ObjectIdWriter objectIdWriter, Object filterId) protectedBeanSerializerBase(BeanSerializerBase src, NameTransformer unwrapper) Copy-constructor that will also rename properties with given prefix (if it's non-empty) -
Method Summary
Modifier and TypeMethodDescriptionprotected void_serializeObjectId(Object bean, JsonGenerator g, SerializationContext ctxt, TypeSerializer typeSer, WritableObjectId objectId) protected void_serializeProperties(Object bean, JsonGenerator g, SerializationContext provider) protected void_serializePropertiesFiltered(Object bean, JsonGenerator g, SerializationContext provider, Object filterId) Alternative serialization method that gets called when there is aPropertyFilterthat needs to be called to determine which properties are to be serialized (and possibly how)protected void_serializePropertiesMaybeView(Object bean, JsonGenerator g, SerializationContext provider, BeanPropertyWriter[] props) Method called when no JSON Filter is to be applied, but View filtering is in effect and so some of properties may be nulls to check.protected void_serializePropertiesNoView(Object bean, JsonGenerator gen, SerializationContext provider, BeanPropertyWriter[] props) Method called when neither JSON Filter is to be applied, nor view-filtering.protected final void_serializeWithObjectId(Object bean, JsonGenerator g, SerializationContext provider, boolean startEndObject) protected final void_serializeWithObjectId(Object bean, JsonGenerator g, SerializationContext provider, TypeSerializer typeSer) protected final WritableTypeId_typeIdDef(TypeSerializer typeSer, Object bean, JsonToken valueShape) voidacceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) Default implementation specifies no format.protected abstract BeanSerializerBaseMutant factory for creating a variant that output POJO as a JSON Array.booleanHelper method for sub-classes to check if it should be possible to construct an "as-array" serializer.createContextual(SerializationContext ctxt, BeanProperty property) Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property (or, for root values, in which case `null` is passed).protected ValueSerializer<Object>findConvertingSerializer(SerializationContext provider, BeanPropertyWriter prop) Helper method that can be used to see if specified property is annotated to indicate use of a converter for property value (in case of container types, it is container type itself, not key or content type).booleanAccessor for checking if view-processing is enabled for this bean, that is, if it has separate set of properties with view-checking added.Accessor for iterating over logical properties that the type handled by this serializer has, from serialization perspective.intvoidresolve(SerializationContext provider) We need to resolve dependant serializers here to be able to properly handle cyclic type references.abstract voidserialize(Object bean, JsonGenerator gen, SerializationContext provider) Method that can be called to ask implementation to serialize values of type this serializer handles.voidserializeWithType(Object bean, JsonGenerator gen, SerializationContext ctxt, 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.toString()abstract ValueSerializer<Object>unwrappingSerializer(NameTransformer unwrapper) Lets force sub-classes to implement this, to avoid accidental missing of handling...booleanMethod that can be called to see whether this serializer instance will use Object Id to handle cyclic references.protected abstract BeanSerializerBasewithByNameInclusion(Set<String> toIgnore, Set<String> toInclude) Mutant factory used for creating a new instance with additional set of properties to ignore or include (from properties this instance otherwise has)abstract BeanSerializerBasewithFilterId(Object filterId) Mutant factory used for creating a new instance with different filter id (used withJsonFilterannotation)abstract BeanSerializerBasewithObjectIdWriter(ObjectIdWriter objectIdWriter) Mutant factory used for creating a new instance with differentObjectIdWriter.protected abstract BeanSerializerBasewithProperties(BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties) Mutant factory used for creating a new instance with modified set of propertiesMethods inherited from class tools.jackson.databind.ser.std.StdSerializer
_neitherNull, _nonEmpty, _wrapIOFailure, acceptJsonFormatVisitorForBinary, createSchemaNode, createSchemaNode, findAnnotatedContentSerializer, findContextualConvertingSerializer, findFormatFeature, findFormatOverrides, findIncludeOverrides, findPropertyFilter, handledType, isDefaultSerializer, visitArrayFormat, visitArrayFormat, visitFloatFormat, visitIntFormat, visitIntFormat, visitStringFormat, visitStringFormat, wrapAndThrow, wrapAndThrowMethods inherited from class tools.jackson.databind.ValueSerializer
getDelegatee, isEmpty, isUnwrappingSerializer, replaceDelegatee, withFormatOverrides, withIgnoredProperties
-
Field Details
-
NAME_FOR_OBJECT_REF
-
NO_PROPS
-
_beanType
-
_props
Writers used for outputting actual property values -
_filteredProps
Optional filters used to suppress output of properties that are only to be included in certain views -
_propertyFilterId
Id of the bean property filter to use, if any; null if none. -
_typeId
If using custom type ids (usually via getter, or field), this is the reference to that member. -
_objectIdWriter
If this POJO can be alternatively serialized using just an object id to denote a reference to previously serialized object, this Object will handle details. -
_serializationShape
Requested shape from bean class annotations.
-
-
Constructor Details
-
BeanSerializerBase
protected BeanSerializerBase(JavaType type, BeanSerializerBuilder builder, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties) Constructor used byBeanSerializerBuilderto create an instance- Parameters:
type- Nominal type of values handled by this serializerbuilder- Builder for accessing other collected information
-
BeanSerializerBase
Copy-constructor that is useful for sub-classes that just want to copy all super-class properties without modifications. -
BeanSerializerBase
protected BeanSerializerBase(BeanSerializerBase src, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties) -
BeanSerializerBase
-
BeanSerializerBase
protected BeanSerializerBase(BeanSerializerBase src, ObjectIdWriter objectIdWriter, Object filterId) -
BeanSerializerBase
-
BeanSerializerBase
Copy-constructor that will also rename properties with given prefix (if it's non-empty)
-
-
Method Details
-
withObjectIdWriter
Mutant factory used for creating a new instance with differentObjectIdWriter. -
withByNameInclusion
protected abstract BeanSerializerBase withByNameInclusion(Set<String> toIgnore, Set<String> toInclude) Mutant factory used for creating a new instance with additional set of properties to ignore or include (from properties this instance otherwise has) -
asArraySerializer
Mutant factory for creating a variant that output POJO as a JSON Array. Implementations may ignore this request if output as array is not possible (either at all, or reliably). -
withFilterId
Mutant factory used for creating a new instance with different filter id (used withJsonFilterannotation)- Overrides:
withFilterIdin classValueSerializer<Object>
-
withProperties
protected abstract BeanSerializerBase withProperties(BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties) Mutant factory used for creating a new instance with modified set of properties -
unwrappingSerializer
Lets force sub-classes to implement this, to avoid accidental missing of handling...- Overrides:
unwrappingSerializerin classValueSerializer<Object>- Parameters:
unwrapper- Name transformation to use to convert between names of unwrapper properties
-
resolve
We need to resolve dependant serializers here to be able to properly handle cyclic type references.- Overrides:
resolvein classValueSerializer<Object>- Parameters:
provider- Currently active serialization context.
-
findConvertingSerializer
protected ValueSerializer<Object> findConvertingSerializer(SerializationContext provider, BeanPropertyWriter prop) Helper method that can be used to see if specified property is annotated to indicate use of a converter for property value (in case of container types, it is container type itself, not key or content type). -
createContextual
Description copied from class:ValueSerializerMethod called to see if a different (or differently configured) serializer is needed to serialize values of specified property (or, for root values, in which case `null` is passed). Note that instance that this method is called on is typically shared one and as a result method should NOT modify this instance but rather construct and return a new instance. This instance should only be returned as-is, in case it is already suitable for use.Note that method is only called once per POJO property, and for the first usage as root value serializer; it is not called for every serialization, as doing that would have significant performance impact; most serializers cache contextual instances for future use.
- Overrides:
createContextualin classValueSerializer<Object>- Parameters:
ctxt- Context to use for accessing config, other serializersproperty- Property (defined by one or more accessors - field or method - used for accessing logical property value) for which serializer is used to be used; or, `null` for root value (or in cases where caller does not have this information, which is handled as root value case).- Returns:
- Serializer to use for serializing values of specified property; may be this instance or a new instance.
-
properties
Description copied from class:ValueSerializerAccessor for iterating over logical properties that the type handled by this serializer has, from serialization perspective. Actual type of properties, if any, will beBeanPropertyWriter. Of standard Jackson serializers, onlyBeanSerializerexposes properties.- Overrides:
propertiesin classValueSerializer<Object>
-
propertyCount
public int propertyCount()- Since:
- 3.0
-
hasViewProperties
public boolean hasViewProperties()Accessor for checking if view-processing is enabled for this bean, that is, if it has separate set of properties with view-checking added.- Since:
- 3.0
-
getFilterId
- Since:
- 3.0
-
canCreateArraySerializer
public boolean canCreateArraySerializer()Helper method for sub-classes to check if it should be possible to construct an "as-array" serializer. Returns if all of following hold true:- have Object Id (may be allowed in future)
- have "any getter"
- Since:
- 3.0
-
usesObjectId
public boolean usesObjectId()Description copied from class:ValueSerializerMethod that can be called to see whether this serializer instance will use Object Id to handle cyclic references.- Overrides:
usesObjectIdin classValueSerializer<Object>
-
serialize
public abstract void serialize(Object bean, JsonGenerator gen, SerializationContext provider) throws JacksonException Description copied from class:ValueSerializerMethod that can be called to ask implementation to serialize values of type this serializer handles.- Specified by:
serializein classStdSerializer<Object>- Parameters:
bean- Value to serialize; can not be null.gen- Generator used to output resulting Json contentprovider- Context that can be used to get serializers for serializing Objects value contains, if any.- Throws:
JacksonException
-
serializeWithType
public void serializeWithType(Object bean, JsonGenerator gen, SerializationContext ctxt, TypeSerializer typeSer) throws JacksonException Description copied from class:ValueSerializerMethod that can be called to ask implementation to serialize values of type this serializer handles, using specified type serializer for embedding necessary type information.Default implementation will throw
UnsupportedOperationExceptionto indicate that proper type handling needs to be implemented.For simple datatypes written as a single scalar value (JSON String, Number, Boolean), implementation would look like:
// note: method to call depends on whether this type is serialized as JSON scalar, object or Array! typeSer.writeTypePrefixForScalar(value, gen); serialize(value, gen, provider); typeSer.writeTypeSuffixForScalar(value, gen);
and implementations for type serialized as JSON Arrays or Objects would differ slightly, asSTART-ARRAY/END-ARRAYandSTART-OBJECT/END-OBJECTpairs need to be properly handled with respect to serializing of contents.- Overrides:
serializeWithTypein classValueSerializer<Object>- Parameters:
bean- Value to serialize; can not be null.gen- Generator used to output resulting Json contentctxt- Context that can be used to get serializers for serializing Objects value contains, if any.typeSer- Type serializer to use for including type information- Throws:
JacksonException
-
_serializeWithObjectId
protected final void _serializeWithObjectId(Object bean, JsonGenerator g, SerializationContext provider, boolean startEndObject) throws JacksonException - Throws:
JacksonException
-
_serializeWithObjectId
protected final void _serializeWithObjectId(Object bean, JsonGenerator g, SerializationContext provider, TypeSerializer typeSer) throws JacksonException - Throws:
JacksonException
-
_serializeObjectId
protected void _serializeObjectId(Object bean, JsonGenerator g, SerializationContext ctxt, TypeSerializer typeSer, WritableObjectId objectId) throws JacksonException - Throws:
JacksonException
-
_typeIdDef
protected final WritableTypeId _typeIdDef(TypeSerializer typeSer, Object bean, JsonToken valueShape) -
_serializePropertiesNoView
protected void _serializePropertiesNoView(Object bean, JsonGenerator gen, SerializationContext provider, BeanPropertyWriter[] props) throws JacksonException Method called when neither JSON Filter is to be applied, nor view-filtering. This means that all property writers are non null and can be called directly.- Throws:
JacksonException- Since:
- 3.0
-
_serializePropertiesMaybeView
protected void _serializePropertiesMaybeView(Object bean, JsonGenerator g, SerializationContext provider, BeanPropertyWriter[] props) throws JacksonException Method called when no JSON Filter is to be applied, but View filtering is in effect and so some of properties may be nulls to check.- Throws:
JacksonException- Since:
- 3.0
-
_serializePropertiesFiltered
protected void _serializePropertiesFiltered(Object bean, JsonGenerator g, SerializationContext provider, Object filterId) throws JacksonException Alternative serialization method that gets called when there is aPropertyFilterthat needs to be called to determine which properties are to be serialized (and possibly how)- Throws:
JacksonException
-
_serializeProperties
protected void _serializeProperties(Object bean, JsonGenerator g, SerializationContext provider) throws JacksonException - Throws:
JacksonException
-
acceptJsonFormatVisitor
Description copied from class:StdSerializerDefault implementation specifies no format. This behavior is usually overriden by custom serializers.- Specified by:
acceptJsonFormatVisitorin interfaceJsonFormatVisitable- Overrides:
acceptJsonFormatVisitorin classStdSerializer<Object>typeHint- Type of element (entity like property) being visited
-
toString
-