Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.datatype.hibernate5

public Class PersistentCollectionSerializer

extends ContainerSerializer<Object>
implements ContextualSerializer, ResolvableSerializer
Class Inheritance
All Implemented Interfaces
com.fasterxml.jackson.databind.ser.ResolvableSerializer, com.fasterxml.jackson.databind.ser.ContextualSerializer
Imports
java.io.IOException, java.util.*, javax.persistence.*, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper, com.fasterxml.jackson.databind.jsontype.TypeSerializer, com.fasterxml.jackson.databind.ser.ContainerSerializer, .ContextualSerializer, .ResolvableSerializer, com.fasterxml.jackson.databind.util.NameTransformer, com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module.Feature, org.hibernate.FlushMode, .Hibernate, .Session, .SessionFactory, org.hibernate.collection.spi.PersistentCollection, org.hibernate.engine.spi.PersistenceContext, .SessionFactoryImplementor, .SessionImplementor, org.hibernate.mapping.Bag, org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl

References Deprecated

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

See corresponding docs for further information.

Wrapper serializer used to handle aspects of lazy loading that can be used for Hibernate collection datatypes; which includes both Collection and Map types (unlike in JDK).

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
protected final int
_features

Hibernate-module features set, if any.

protected final JavaType
_originalType

Type for which underlying serializer was created.

protected final JsonSerializer<Object>
_serializer

Serializer that does actual value serialization when value is available (either already or with forced access).

protected final SessionFactory
_sessionFactory

References Deprecated SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.
private static final long

Constructor Summary

AccessConstructor and Description
public
PersistentCollectionSerializer(JavaType containerType, JsonSerializer<?> serializer, int features, SessionFactory sessionFactory)
References Deprecated SessionFactory is deprecated or references (maybe indirectly) at least one deprecated element.

protected
PersistentCollectionSerializer(PersistentCollectionSerializer base, JsonSerializer<?> serializer)
References Deprecated PersistentCollectionSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

Method Summary

Modifier and TypeMethod and Description
protected ContainerSerializer<?>
_containerSerializer()
References Deprecated ContainerSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

protected PersistentCollectionSerializer
_withSerializer(JsonSerializer<?> ser)
References Deprecated PersistentCollectionSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

protected ContainerSerializer<?>
_withValueTypeSerializer(TypeSerializer vts)

Implements abstract com.fasterxml.jackson.databind.ser.ContainerSerializer._withValueTypeSerializer.

References Deprecated ContainerSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

Method that needs to be implemented to allow construction of a new serializer object with given TypeSerializer, used when addition type information is to be embedded.

public void
private Object
private Object
convertToList(List<?> value)

private Object
convertToMap(Map<?, ?> value)

private Object
convertToSet(Set<?> value)

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.

We need to resolve actual serializer once we know the context; specifically must know type of property being serialized.

protected Object
public JsonSerializer<?>
getContentSerializer()

Implements abstract com.fasterxml.jackson.databind.ser.ContainerSerializer.getContentSerializer.

Accessor for serializer used for serializing contents (List and array elements, Map values etc) of the container for which this serializer is used, if it is known statically.

public JavaType
getContentType()

Implements abstract com.fasterxml.jackson.databind.ser.ContainerSerializer.getContentType.

Accessor for finding declared (static) element type for type this serializer is used for.

public boolean
hasSingleElement(Object value)

Implements abstract com.fasterxml.jackson.databind.ser.ContainerSerializer.hasSingleElement.

Method called to determine if the given value (of type handled by this serializer) contains exactly one element.

private void
initializeCollection(PersistentCollection coll, Session session)
References Deprecated Session is deprecated or references (maybe indirectly) at least one deprecated element.

public boolean
isEmpty(SerializerProvider provider, 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 boolean
isUnwrappingSerializer()

Overrides com.fasterxml.jackson.databind.JsonSerializer.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.

private Session
openTemporarySessionForLoading(PersistentCollection coll)
References Deprecated Session is deprecated or references (maybe indirectly) at least one deprecated element.

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
g
,
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
g
,
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.

public PersistentCollectionSerializer
unwrappingSerializer(NameTransformer
Name transformation to use to convert between names of unwrapper properties
unwrapper
)

Overrides com.fasterxml.jackson.databind.JsonSerializer.unwrappingSerializer.

References Deprecated PersistentCollectionSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

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

protected boolean
usesLazyLoading(BeanProperty property)

Method called to see whether given property indicates it uses lazy resolution of reference contained.

public boolean
usesObjectId()

Overrides com.fasterxml.jackson.databind.JsonSerializer.usesObjectId.

Method that can be called to see whether this serializer instance will use Object Id to handle cyclic references.

Inherited from com.fasterxml.jackson.databind.ser.ContainerSerializer:
hasContentTypeAnnotationwithValueTypeSerializer

Field Detail

_featuresback to summary
protected final int _features

Hibernate-module features set, if any.

_originalTypeback to summary
protected final JavaType _originalType

Type for which underlying serializer was created.

Since
2.7
_serializerback to summary
protected final JsonSerializer<Object> _serializer

Serializer that does actual value serialization when value is available (either already or with forced access).

_sessionFactoryback to summary
protected final SessionFactory _sessionFactory

References Deprecated

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

See corresponding docs for further information.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.fasterxml.jackson.databind.ser.std.StdSerializer.serialVersionUID.

Constructor Detail

PersistentCollectionSerializerback to summary
public PersistentCollectionSerializer(JavaType containerType, JsonSerializer<?> serializer, int features, SessionFactory sessionFactory)

References Deprecated

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

See corresponding docs for further information.

Annotations
@SuppressWarnings:unchecked
PersistentCollectionSerializerback to summary
protected PersistentCollectionSerializer(PersistentCollectionSerializer base, JsonSerializer<?> serializer)

References Deprecated

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

See corresponding docs for further information.

Annotations
@SuppressWarnings:unchecked
Since
2.7

Method Detail

_containerSerializerback to summary
protected ContainerSerializer<?> _containerSerializer()

References Deprecated

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

See corresponding docs for further information.

_withSerializerback to summary
protected PersistentCollectionSerializer _withSerializer(JsonSerializer<?> ser)

References Deprecated

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

See corresponding docs for further information.

_withValueTypeSerializerback to summary
protected ContainerSerializer<?> _withValueTypeSerializer(TypeSerializer vts)

Implements abstract com.fasterxml.jackson.databind.ser.ContainerSerializer._withValueTypeSerializer.

Doc from com.fasterxml.jackson.databind.ser.ContainerSerializer._withValueTypeSerializer.

References Deprecated

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

See corresponding docs for further information.

Method that needs to be implemented to allow construction of a new serializer object with given TypeSerializer, used when addition type information is to be embedded.

Annotations
@Override
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.ser.std.StdSerializer.acceptJsonFormatVisitor.

Default implementation specifies no format. This behavior is usually overriden by custom serializers.

Parameters
typeHint:JavaType

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

Type of element (entity like property) being visited

Annotations
@Override
convertToJavaCollectionback to summary
private Object convertToJavaCollection(Object value)
convertToListback to summary
private Object convertToList(List<?> value)
convertToMapback to summary
private Object convertToMap(Map<?, ?> value)
convertToSetback to summary
private Object convertToSet(Set<?> value)
createContextualback to summary
public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property) throws JsonMappingException

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

We need to resolve actual serializer once we know the context; specifically must know type of property being serialized.

Parameters
provider:SerializerProvider

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

Serializer provider to use for accessing config, other serializers

property:BeanProperty

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

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<?>

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

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

Annotations
@Override
findLazyValueback to summary
protected Object findLazyValue(PersistentCollection coll)
getContentSerializerback to summary
public JsonSerializer<?> getContentSerializer()

Implements abstract com.fasterxml.jackson.databind.ser.ContainerSerializer.getContentSerializer.

Doc from com.fasterxml.jackson.databind.ser.ContainerSerializer.getContentSerializer.

Accessor for serializer used for serializing contents (List and array elements, Map values etc) of the container for which this serializer is used, if it is known statically. Note that for dynamic types this may return null; if so, caller has to instead use getContentType() and com.fasterxml.jackson.databind.SerializerProvider#findContentValueSerializer.

Annotations
@Override
getContentTypeback to summary
public JavaType getContentType()

Implements abstract com.fasterxml.jackson.databind.ser.ContainerSerializer.getContentType.

Doc from com.fasterxml.jackson.databind.ser.ContainerSerializer.getContentType.

Accessor for finding declared (static) element type for type this serializer is used for.

Annotations
@Override
hasSingleElementback to summary
public boolean hasSingleElement(Object value)

Implements abstract com.fasterxml.jackson.databind.ser.ContainerSerializer.hasSingleElement.

Doc from com.fasterxml.jackson.databind.ser.ContainerSerializer.hasSingleElement.

Method called to determine if the given value (of type handled by this serializer) contains exactly one element.

Note

although it might seem sensible to instead define something like "getElementCount()" method, this would not work well for containers that do not keep track of size (like linked lists may not).

Note, too, that as of now (2.9) this method is only called by serializer itself; and specifically is not used for non-array/collection types like Map or Map.Entry instances.

Annotations
@Override
initializeCollectionback to summary
private void initializeCollection(PersistentCollection coll, Session session)

References Deprecated

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

See corresponding docs for further information.

isEmptyback to summary
public boolean isEmpty(SerializerProvider provider, 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
isUnwrappingSerializerback to summary
public boolean isUnwrappingSerializer()

Overrides com.fasterxml.jackson.databind.JsonSerializer.isUnwrappingSerializer.

Doc from com.fasterxml.jackson.databind.JsonSerializer.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.

Annotations
@Override
openTemporarySessionForLoadingback to summary
private Session openTemporarySessionForLoading(PersistentCollection coll)

References Deprecated

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

See corresponding docs for further information.

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 g, 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.

g: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 g, 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.

g: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
unwrappingSerializerback to summary
public PersistentCollectionSerializer unwrappingSerializer(NameTransformer unwrapper)

Overrides com.fasterxml.jackson.databind.JsonSerializer.unwrappingSerializer.

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

References Deprecated

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

See corresponding docs for further information.

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

Parameters
unwrapper:NameTransformer

Name transformation to use to convert between names of unwrapper properties

Annotations
@Override
usesLazyLoadingback to summary
protected boolean usesLazyLoading(BeanProperty property)

Method called to see whether given property indicates it uses lazy resolution of reference contained.

usesObjectIdback to summary
public boolean usesObjectId()

Overrides com.fasterxml.jackson.databind.JsonSerializer.usesObjectId.

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

Method that can be called to see whether this serializer instance will use Object Id to handle cyclic references.

Annotations
@Override
com.fasterxml.jackson.datatype.hibernate5 back to summary

protected Class PersistentCollectionSerializer.SessionReader

extends Object
Class Inheritance
  • java.lang.Object
  • com.fasterxml.jackson.datatype.hibernate5.PersistentCollectionSerializer.SessionReader

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static boolean
isJTA(Session session)
References Deprecated Session is deprecated or references (maybe indirectly) at least one deprecated element.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SessionReaderback to summary
protected SessionReader()

Method Detail

isJTAback to summary
public static boolean isJTA(Session session)

References Deprecated

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

See corresponding docs for further information.