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

public Class StdDelegatingSerializer

extends StdSerializer<Object>
implements ContextualSerializer, ResolvableSerializer, JsonFormatVisitable
Class Inheritance
All Implemented Interfaces
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable, com.fasterxml.jackson.databind.ser.ResolvableSerializer, com.fasterxml.jackson.databind.ser.ContextualSerializer
Annotations
@SuppressWarnings:serial
Imports
com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable, .JsonFormatVisitorWrapper, com.fasterxml.jackson.databind.jsontype.TypeSerializer, com.fasterxml.jackson.databind.ser.ContextualSerializer, .ResolvableSerializer, com.fasterxml.jackson.databind.util.ClassUtil, .Converter, java.io.IOException, java.lang.reflect.Type

References Deprecated

StdSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Serializer implementation where given Java type is first converted to an intermediate "delegate type" (using a configured Converter, and then this delegate value is serialized by Jackson.

Note that although types may be related, they must not be same; trying to do this will result in an exception.

Since
2.1

Field Summary

Modifier and TypeField and Description
protected final Converter<Object, ?>
protected final JsonSerializer<Object>
_delegateSerializer

Underlying serializer for type T.

protected final JavaType
_delegateType

Fully resolved delegate type, with generic information if any available.

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

Constructor Summary

AccessConstructor and Description
public
public <T>
StdDelegatingSerializer(Class<T> cls, Converter<T, ?> converter)

public
StdDelegatingSerializer(Converter<Object, ?> converter, JavaType delegateType, JsonSerializer<?> delegateSerializer)

Method Summary

Modifier and TypeMethod and Description
protected JsonSerializer<Object>
_findSerializer(Object value, SerializerProvider serializers)

Helper method used for locating serializer to use in dynamic use case, where actual type value gets converted to is not specified beyond basic java.lang.Object, and where serializer needs to be located dynamically based on actual value type.

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.

protected Object

Returns:

Result of conversion
convertValue
(Object
Value to convert
value
)

Method called to convert from source Java value into delegate value (which will be serialized using standard Jackson serializer for delegate type)

The default implementation uses configured Converter to do conversion.

public JsonSerializer<?>
createContextual(SerializerProvider
Serializer provider to use for accessing config, other serializers
provider
,
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.

Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property.

protected Converter<Object, ?>
public JsonSerializer<?>
getDelegatee()

Overrides com.fasterxml.jackson.databind.JsonSerializer.getDelegatee.

Accessor that can be used to determine if this serializer uses another serializer for actual serialization, by delegating calls.

public JsonNode
getSchema(SerializerProvider
The serializer provider.
provider
,
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 JsonNode
getSchema(SerializerProvider
The serializer provider.
provider
,
Type
A hint about the type.
typeHint
,
boolean
Is the type optional
isOptional
)

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 prov, Object value)

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).

public void
resolve(SerializerProvider
Provider that has constructed serializer this method is called on.
provider
)

Implements com.fasterxml.jackson.databind.ser.ResolvableSerializer.resolve.

Method called after SerializerProvider has registered the serializer, but before it has returned it to the caller.

public void
serialize(Object
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.
provider
)

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.
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.
provider
,
TypeSerializer
Type serializer to use for including type information
typeSer
)

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.

protected StdDelegatingSerializer
withDelegate(Converter<Object, ?> converter, JavaType delegateType, JsonSerializer<?> delegateSerializer)
References Deprecated StdDelegatingSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

Method used for creating resolved contextual instances.

Inherited from com.fasterxml.jackson.databind.ser.std.StdSerializer:
_neitherNull_nonEmptycreateSchemaNodecreateSchemaNodefindAnnotatedContentSerializerfindContextualConvertingSerializerfindConvertingContentSerializerfindFormatFeaturefindFormatOverridesfindIncludeOverridesfindPropertyFilterhandledTypeisDefaultSerializervisitArrayFormatvisitArrayFormatvisitFloatFormatvisitIntFormatvisitIntFormatvisitStringFormatvisitStringFormatwrapAndThrowwrapAndThrow

Field Detail

_converterback to summary
protected final Converter<Object, ?> _converter
_delegateSerializerback to summary
protected final JsonSerializer<Object> _delegateSerializer

Underlying serializer for type T.

_delegateTypeback to summary
protected final JavaType _delegateType

Fully resolved delegate type, with generic information if any available.

Constructor Detail

StdDelegatingSerializerback to summary
public StdDelegatingSerializer(Converter<?, ?> converter)
Annotations
@SuppressWarnings:unchecked
StdDelegatingSerializerback to summary
public <T> StdDelegatingSerializer(Class<T> cls, Converter<T, ?> converter)
Annotations
@SuppressWarnings:unchecked
StdDelegatingSerializerback to summary
public StdDelegatingSerializer(Converter<Object, ?> converter, JavaType delegateType, JsonSerializer<?> delegateSerializer)
Annotations
@SuppressWarnings:unchecked

Method Detail

_findSerializerback to summary
protected JsonSerializer<Object> _findSerializer(Object value, SerializerProvider serializers) throws JsonMappingException

Helper method used for locating serializer to use in dynamic use case, where actual type value gets converted to is not specified beyond basic java.lang.Object, and where serializer needs to be located dynamically based on actual value type.

Since
2.6
acceptJsonFormatVisitorback to summary
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException

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

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

Doc from com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Get the representation of the schema to which this serializer will conform.

Parameters
typeHint:JavaType

Type of element (entity like property) being visited

Annotations
@Override
convertValueback to summary
protected Object convertValue(Object value)

Method called to convert from source Java value into delegate value (which will be serialized using standard Jackson serializer for delegate type)

The default implementation uses configured Converter to do conversion.

Parameters
value:Object

Value to convert

Returns:Object

Result of conversion

createContextualback to summary
public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property) throws JsonMappingException

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

Doc from com.fasterxml.jackson.databind.ser.ContextualSerializer.createContextual.

Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property. 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.

Parameters
provider:SerializerProvider

Serializer provider to use for accessing config, other serializers

property: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)

Returns:JsonSerializer<?>

Serializer to use for serializing values of specified property; may be this instance or a new instance.

Annotations
@Override
getConverterback to summary
protected Converter<Object, ?> getConverter()
getDelegateeback to summary
public JsonSerializer<?> getDelegatee()

Overrides com.fasterxml.jackson.databind.JsonSerializer.getDelegatee.

Doc from com.fasterxml.jackson.databind.JsonSerializer.getDelegatee.

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.

Returns:JsonSerializer<?>

Serializer this serializer delegates calls to, if null; null otherwise.

Annotations
@Override
getSchemaback to summary
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException

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

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

Doc from com.fasterxml.jackson.databind.ser.std.StdSerializer.getSchema.

Deprecated

Since 2.15

Default implementation simply claims type is "string"; usually overriden by custom serializers.

Parameters
provider:SerializerProvider

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

The serializer provider.

typeHint:Type

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

A hint about the type.

Returns:JsonNode

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Json-schema for this serializer.

Annotations
@Deprecated
@Override
getSchemaback to summary
public JsonNode getSchema(SerializerProvider provider, Type typeHint, boolean isOptional) throws JsonMappingException

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

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

Doc from com.fasterxml.jackson.databind.ser.std.StdSerializer.getSchema.

Deprecated

Since 2.15

Default implementation simply claims type is "string"; usually overriden by custom serializers.

Parameters
provider:SerializerProvider

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

The serializer provider.

typeHint:Type

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

A hint about the type.

isOptional:boolean

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Is the type optional

Returns:JsonNode

Doc from com.fasterxml.jackson.databind.jsonschema.SchemaAware.getSchema.

Json-schema for this serializer.

Annotations
@Deprecated
@Override
isEmptyback to summary
public boolean isEmpty(SerializerProvider prov, Object value)

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

Doc from 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).

Default implementation will consider only null values to be empty.

Note

replaces isEmpty(Object), which was deprecated in 2.5

Annotations
@Override
resolveback to summary
public void resolve(SerializerProvider provider) throws JsonMappingException

Implements com.fasterxml.jackson.databind.ser.ResolvableSerializer.resolve.

Doc from com.fasterxml.jackson.databind.ser.ResolvableSerializer.resolve.

Method called after SerializerProvider has registered the serializer, but before it has returned it to the caller. Called object can then resolve its dependencies to other types, including self-references (direct or indirect).

Note that this method does NOT return serializer, since resolution is not allowed to change actual serializer to use.

Parameters
provider:SerializerProvider

Provider that has constructed serializer this method is called on.

Annotations
@Override
serializeback to summary
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException

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

Doc from com.fasterxml.jackson.databind.JsonSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Parameters
value:Object

Value to serialize; can not be null.

gen:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

Annotations
@Override
serializeWithTypeback to summary
public void serializeWithType(Object value, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException

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

Doc from 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.

Default implementation will throw UnsupportedOperationException to 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, as START-ARRAY/END-ARRAY and START-OBJECT/END-OBJECT pairs need to be properly handled with respect to serializing of contents.
Parameters
value:Object

Value to serialize; can not be null.

gen:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

typeSer:TypeSerializer

Type serializer to use for including type information

Annotations
@Override
withDelegateback to summary
protected StdDelegatingSerializer withDelegate(Converter<Object, ?> converter, JavaType delegateType, JsonSerializer<?> delegateSerializer)

References Deprecated

StdDelegatingSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Method used for creating resolved contextual instances. Must be overridden when sub-classing.