ObjectMapper (and
other chained JsonSerializers too) to serialize Objects of
arbitrary types into JSON, using provided JsonGenerator.
com.fasterxml.jackson.databind.ser.std.StdSerializer instead
of this class, since it will implement many of optional
methods of this class.Note
various serialize methods are never (to be) called
with null values -- caller must handle null values, usually
by calling SerializerProvider#findNullValueSerializer to obtain
serializer to use.
This also means that custom serializers cannot be directly used to change
the output to produce when serializing null values.
If serializer is an aggregate one -- meaning it delegates handling of some
of its contents by using other serializer(s) -- it typically also needs
to implement com.,
which can locate secondary serializers needed. This is important to allow dynamic
overrides of serializers; separate call interface is needed to separate
resolution of secondary serializers (which may have cyclic link back
to serializer itself, directly or indirectly).
In addition, to support per-property annotations (to configure aspects
of serialization on per-property basis), serializers may want
to implement
com.,
which allows specialization of serializers: call to
com.
is passed information on property, and can create a newly configured
serializer for handling that particular property.
If both
com. and
com.
are implemented, resolution of serializers occurs before
contextualization.
| Modifier and Type | Class and Description |
|---|---|
| public abstract static class | JsonSerializer.None
This marker class is only to be used with annotations, to indicate that no serializer is configured. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType
Type of element (entity like property) being visited type)Implements com. JsonFormatVisitorWrapper#expectAnyFormat(JavaType).
|
| public JsonSerializer | Returns: Serializer this serializer delegates calls to, if null; null otherwise.Accessor that can be used to determine if this serializer uses another serializer for actual serialization, by delegating calls. |
| public Class | |
| public boolean | isEmpty(T value)
Deprecated
Since 2.5 Use
Method called to check whether given serializable value is
considered "empty" value (for purposes of suppressing serialization
of empty values).
isEmpty(SerializerProvider, Object) instead;
will be removed from 3.0
|
| public boolean | isEmpty(SerializerProvider provider, T value)
Method called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values). |
| public boolean | isUnwrappingSerializer()
Accessor for checking whether this serializer is an "unwrapping" serializer; this is necessary to know since it may also require caller to suppress writing of the leading property name. |
| public Iterator | properties()
Accessor for iterating over logical properties that the type handled by this serializer has, from serialization perspective. |
| public JsonSerializer | replaceDelegatee(JsonSerializer<?> delegatee)
Method that can be called to try to replace serializer this serializer delegates calls to. |
| public abstract void | serialize(T
Value to serialize; can not be null. value, JsonGenerator Generator used to output resulting Json content gen, SerializerProvider Provider that can be used to get serializers for
serializing Objects value contains, if any. serializers)Method that can be called to ask implementation to serialize values of type this serializer handles. |
| public void | serializeWithType(T
Value to serialize; can not be null. value, JsonGenerator Generator used to output resulting Json content gen, SerializerProvider Provider that can be used to get serializers for
serializing Objects value contains, if any. serializers, TypeSerializer Type serializer to use for including type information 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. |
| public JsonSerializer | unwrappingSerializer(NameTransformer
Name transformation to use to convert between names
of unwrapper properties unwrapper)Method that will return serializer instance that produces "unwrapped" serialization, if applicable for type being serialized (which is the case for some serializers that produce JSON Objects as output). |
| public boolean | usesObjectId()
Method that can be called to see whether this serializer instance will use Object Id to handle cyclic references. |
| public JsonSerializer | withFilterId(Object filterId)
Mutant factory method that is called if contextual configuration indicates that
a specific filter (as specified by |
| public JsonSerializer | Returns: Serializer instance that without specified set of properties to ignore (if any)Set of property names to ignore for serialization; ignoredProperties)Mutant factory method called to create a new instance after excluding specified set of properties by name, if there is any. |
| JsonSerializer | back to summary |
|---|---|
| public JsonSerializer() | |
| acceptJsonFormatVisitor | back to summary |
|---|---|
| public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType type) throws JsonMappingException Implements com. Default implementation simply calls
| |
| getDelegatee | back to summary |
|---|---|
| public JsonSerializer Accessor that can be used to determine if this serializer uses another serializer for actual serialization, by delegating calls. If so, will return immediate delegate (which itself may delegate to further serializers); otherwise will return null.
| |
| handledType | back to summary |
|---|---|
| public Class Method for accessing type of Objects this serializer can handle. Note that this information is not guaranteed to be exact -- it may be a more generic (super-type) -- but it should not be incorrect (return a non-related type).
Default implementation will return null, which essentially means
same as returning
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty(T value)
Deprecated Since 2.5 Use Method called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values). Default implementation will consider only null values to be empty.
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty(SerializerProvider provider, T value) Method called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values). Default implementation will consider only null values to be empty. Note replaces
| |
| isUnwrappingSerializer | back to summary |
|---|---|
| public boolean isUnwrappingSerializer() Accessor for checking whether this serializer is an "unwrapping" serializer; this is necessary to know since it may also require caller to suppress writing of the leading property name. | |
| properties | back to summary |
|---|---|
| public Iterator Accessor for iterating over logical properties that the type
handled by this serializer has, from serialization perspective.
Actual type of properties, if any, will be
| |
| replaceDelegatee | back to summary |
|---|---|
| public JsonSerializer Method that can be called to try to replace serializer this serializer
delegates calls to. If not supported (either this serializer does not
delegate anything; or it does not want any changes), should either
throw
| |
| serialize | back to summary |
|---|---|
| public abstract void serialize(T value, JsonGenerator gen, SerializerProvider serializers) throws IOException Method that can be called to ask implementation to serialize values of type this serializer handles.
| |
| serializeWithType | back to summary |
|---|---|
| public void serializeWithType(T value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException 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.
Default implementation will throw 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, as START-ARRAY/END-ARRAY and
START-OBJECT/END-OBJECT pairs
need to be properly handled with respect to serializing of contents.
| |
| unwrappingSerializer | back to summary |
|---|---|
| public JsonSerializer Method that will return serializer instance that produces "unwrapped" serialization, if applicable for type being serialized (which is the case for some serializers that produce JSON Objects as output). If no unwrapped serializer can be constructed, will simply return serializer as-is. Default implementation just returns serializer as-is, indicating that no unwrapped variant exists
| |
| usesObjectId | back to summary |
|---|---|
| public boolean usesObjectId() Method that can be called to see whether this serializer instance will use Object Id to handle cyclic references. | |
| withFilterId | back to summary |
|---|---|
| public JsonSerializer Mutant factory method that is called if contextual configuration indicates that
a specific filter (as specified by
Default implementation simply returns
| |
| withIgnoredProperties | back to summary |
|---|---|
| public JsonSerializer Mutant factory method called to create a new instance after excluding specified set of properties by name, if there is any.
| |
Specifically, this class is to be used as the marker for
annotation com..
| Access | Constructor and Description |
|---|---|
| public |
| None | back to summary |
|---|---|
| public None() | |