Top Description Methods
com.fasterxml.jackson.databind.ser

public Interface ContextualSerializer

Known Direct Implementers
com.fasterxml.jackson.databind.ser.impl.MapEntrySerializer, com.fasterxml.jackson.databind.ser.impl.StringArraySerializer, com.fasterxml.jackson.databind.ser.impl.TypeWrappedSerializer, com.fasterxml.jackson.databind.ser.std.InetAddressSerializer, com.fasterxml.jackson.databind.ser.std.ArraySerializerBase, com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase, com.fasterxml.jackson.databind.ser.std.BeanSerializerBase, com.fasterxml.jackson.databind.ser.std.BooleanSerializer, com.fasterxml.jackson.databind.ser.std.BooleanSerializer.AsNumber, com.fasterxml.jackson.databind.ser.std.DateTimeSerializerBase, com.fasterxml.jackson.databind.ser.std.EnumSerializer, com.fasterxml.jackson.databind.ser.std.JsonValueSerializer, com.fasterxml.jackson.databind.ser.std.MapSerializer, com.fasterxml.jackson.databind.ser.std.NumberSerializer, com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base, com.fasterxml.jackson.databind.ser.std.ObjectArraySerializer, com.fasterxml.jackson.databind.ser.std.ReferenceTypeSerializer, com.fasterxml.jackson.databind.ser.std.StaticListSerializerBase, com.fasterxml.jackson.databind.ser.std.StdDelegatingSerializer, com.fasterxml.jackson.databind.ser.std.UUIDSerializer, com.fasterxml.jackson.databind.ext.CoreXMLSerializers.XMLGregorianCalendarSerializer
Imports
com.fasterxml.jackson.databind.*

Add-on interface that JsonSerializers can implement to get a callback that can be used to create contextual instances of serializer to use for handling properties of supported type. This can be useful for serializers that can be configured by annotations, or should otherwise have differing behavior depending on what kind of property is being serialized.

Note that in cases where serializer needs both contextualization and resolution -- that is, implements both this interface and ResolvableSerializer -- resolution via ResolvableSerializer occurs first, and contextual resolution (via this interface) later on.

Method Summary

Modifier and TypeMethod and Description
public JsonSerializer<?>

Returns:

Serializer to use for serializing values of specified property; may be this instance or a new instance.
createContextual
(SerializerProvider
Serializer provider to use for accessing config, other serializers
prov
,
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
)

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

Method Detail

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

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
prov: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.