Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.databind.ser.std

public Class JsonValueSerializer

extends StdSerializer<Object>
implements ContextualSerializer, JsonFormatVisitable
Class Inheritance
All Implemented Interfaces
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable, com.fasterxml.jackson.databind.ser.ContextualSerializer
Annotations
@SuppressWarnings:serial
@JacksonStdImpl
Imports
java.io.IOException, java.lang.reflect.InvocationTargetException, .Type, java.util.Collections, .LinkedHashSet, .Set, com.fasterxml.jackson.annotation.JsonIgnoreProperties, .JsonTypeInfo.As, com.fasterxml.jackson.core.*, com.fasterxml.jackson.core.type.WritableTypeId, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.annotation.JacksonStdImpl, com.fasterxml.jackson.databind.introspect.AnnotatedMember, com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable, .JsonFormatVisitorWrapper, .JsonStringFormatVisitor, com.fasterxml.jackson.databind.jsontype.TypeIdResolver, .TypeSerializer, com.fasterxml.jackson.databind.ser.BeanSerializer, .ContextualSerializer, com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap, com.fasterxml.jackson.databind.util.ClassUtil

Deprecated

as a consequence of StdSerializer being deprecated. See corresponding docs for further information.

Serializer class that can serialize Object that have a com.fasterxml.jackson.annotation.JsonValue annotation to indicate that serialization should be done by calling the method annotated, and serializing result it returns.

Implementation Note

we will post-process resulting serializer (much like what is done with BeanSerializer) to figure out actual serializers for final types. This must be done from createContextual method, and NOT from constructor; otherwise we could end up with an infinite loop.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
JsonValueSerializer.TypeSerializerRerouter

Silly little wrapper class we need to re-route type serialization so that we can override Object to use for type id (logical type) even when asking serialization of something else (delegate type)

Field Summary

Modifier and TypeField and Description
protected final AnnotatedMember
protected transient PropertySerializerMap
_dynamicSerializers

If value type cannot be statically determined, mapping from runtime value types to serializers are cached in this object.

protected final boolean
_forceTypeInformation

This is a flag that is set in rare (?) cases where this serializer is used for "natural" types (boolean, int, String, double); and where we actually must force type information wrapping, even though one would not normally be added.

protected final Set<String>
_ignoredProperties

Names of properties to ignore from Value class accessed using accessor.

protected final BeanProperty
protected final JsonSerializer<Object>
protected final JavaType
_valueType

Declared type of the value accessed, as declared by accessor.

protected final TypeSerializer
Inherited from com.fasterxml.jackson.databind.ser.std.StdSerializer:
_handledType

Constructor Summary

AccessConstructor and Description
public
JsonValueSerializer(AnnotatedMember accessor, TypeSerializer vts, JsonSerializer<?>
Explicit serializer to use, if caller knows it (which occurs if and only if the "value method" was annotated with com.fasterxml.jackson.databind.annotation.JsonSerialize#using), otherwise null
ser
,
Set<String> ignoredProperties)

public
public
JsonValueSerializer(AnnotatedMember accessor, JsonSerializer<?> ser)

Deprecated Since 2.12
public
JsonValueSerializer(JsonValueSerializer src, BeanProperty property, TypeSerializer vts, JsonSerializer<?> ser, boolean forceTypeInfo)

Deprecated as a consequence of JsonValueSerializer being deprecated.

Method Summary

Modifier and TypeMethod and Description
protected boolean

Returns:

True if method handled callbacks; false if not; in latter case caller will send default callbacks
_acceptJsonFormatVisitorForEnum
(JsonFormatVisitorWrapper visitor, JavaType typeHint, Class<?> enumType)

Overridable helper method used for special case handling of schema information for Enums.

protected JsonSerializer<Object>
private static final Class<Object>
protected static JsonSerializer<Object>

Returns:

Configured serializer with specified properties ignored
_withIgnoreProperties
(JsonSerializer<?>
Serializer to be configured
ser
,
Set<String> ignoredProperties)

Internal helper that configures the provided ser to ignore properties specified by JsonIgnoreProperties.

public void
acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType
Type of element (entity like property) being visited
typeHint
)

Overrides com.fasterxml.jackson.databind.ser.std.StdSerializer.acceptJsonFormatVisitor.

Implements com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Get the representation of the schema to which this serializer will conform.
public static JsonValueSerializer
construct(SerializationConfig config, AnnotatedMember accessor, TypeSerializer vts, JsonSerializer<?> ser)

Deprecated as a consequence of JsonValueSerializer being deprecated.
public JsonSerializer<?>
createContextual(SerializerProvider
Serializer provider to use for accessing config, other serializers
ctxt
,
BeanProperty
Method or field that represents the property (and is used to access value to serialize). Should be available; but there may be cases where caller cannot provide it and null is passed instead (in which case impls usually pass 'this' serializer as is)
property
)

Implements com.fasterxml.jackson.databind.ser.ContextualSerializer.createContextual.

We can try to find the actual serializer for value, if we can statically figure out what the result type must be.
public JsonNode
getSchema(SerializerProvider
The serializer provider.
ctxt
,
Type
A hint about the type.
typeHint
)

Overrides com.fasterxml.jackson.databind.ser.std.StdSerializer.getSchema.

Implements com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Deprecated Since 2.15
Default implementation simply claims type is "string"; usually overriden by custom serializers.
public boolean
isEmpty(SerializerProvider ctxt, Object bean)

Overrides com.fasterxml.jackson.databind.JsonSerializer.isEmpty.

Method called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values).
protected boolean
public void
serialize(Object
Value to serialize; can not be null.
bean
,
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.
ctxt
)

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.
public void
serializeWithType(Object
Value to serialize; can not be null.
bean
,
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.
ctxt
,
TypeSerializer
Type serializer to use for including type information
typeSer0
)

Overrides com.fasterxml.jackson.databind.JsonSerializer.serializeWithType.

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 String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
protected JsonValueSerializer
withResolved(BeanProperty property, TypeSerializer vts, JsonSerializer<?> ser, boolean forceTypeInfo)

Deprecated as a consequence of JsonValueSerializer being deprecated.
Inherited from com.fasterxml.jackson.databind.ser.std.StdSerializer:
_neitherNull_nonEmptycreateSchemaNodecreateSchemaNodefindAnnotatedContentSerializerfindContextualConvertingSerializerfindConvertingContentSerializerfindFormatFeaturefindFormatOverridesfindIncludeOverridesfindPropertyFiltergetSchemahandledTypeisDefaultSerializervisitArrayFormatvisitArrayFormatvisitFloatFormatvisitIntFormatvisitIntFormatvisitStringFormatvisitStringFormatwrapAndThrowwrapAndThrow