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

public Class HibernateProxySerializer

extends JsonSerializer<HibernateProxy>
implements ContextualSerializer
Class Inheritance
All Implemented Interfaces
com.fasterxml.jackson.databind.ser.ContextualSerializer
Imports
java.beans.Introspector, java.io.IOException, java.lang.reflect.Field, .Method, java.util.HashMap, javax.persistence.EntityNotFoundException, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.BeanProperty, .JavaType, .JsonMappingException, .JsonSerializer, .SerializerProvider, com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper, com.fasterxml.jackson.databind.jsontype.TypeSerializer, com.fasterxml.jackson.databind.ser.ContextualSerializer, com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap, com.fasterxml.jackson.databind.util.NameTransformer, org.hibernate.engine.spi.Mapping, .SessionFactoryImplementor, .SessionImplementor, org.hibernate.proxy.HibernateProxy, .LazyInitializer, org.hibernate.proxy.pojo.BasicLazyInitializer

Serializer to use for values proxied using org.hibernate.proxy.HibernateProxy.

Todo

should try to make this work more like Jackson BeanPropertyWriter, possibly sub-classing it -- it handles much of functionality we need, and has access to more information than value serializers (like this one) have.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
HibernateProxySerializer.ProxyReader

Inspects a Hibernate proxy to try and determine the name of the identifier property (Hibernate proxies know the getter of the identifier property because it receives special treatment in the invocation handler).

protected static class
HibernateProxySerializer.ProxySessionReader

Hibernate 5.2 broke abi compatibility of org.hibernate.proxy.LazyInitializer.getSession() The api contract changed from org.hibernate.proxy.LazyInitializer.getSession()Lorg.hibernate.engine.spi.SessionImplementor; to org.hibernate.proxy.LazyInitializer.getSession()Lorg.hibernate.engine.spi.SharedSessionContractImplementor On hibernate 5.2 the interface SessionImplementor extends SharedSessionContractImplementor.

Field Summary

Modifier and TypeField and Description
protected PropertySerializerMap
_dynamicSerializers

For efficient serializer lookup, let's use this; most of the time, there's just one type and one serializer.

protected final boolean
protected final Mapping
protected final boolean
protected final BeanProperty
_property

Property that has proxy value to handle

protected final boolean
protected final NameTransformer
protected final boolean

Constructor Summary

AccessConstructor and Description
public
HibernateProxySerializer(boolean forceLazyLoading)
Deprecated

public
HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier)
Deprecated

public
HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier, Mapping mapping)
Deprecated

public
HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier, boolean nullMissingEntities, Mapping mapping)
Deprecated

public
HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier, boolean nullMissingEntities, Mapping mapping, BeanProperty property)
Deprecated

public
HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier, boolean nullMissingEntities, boolean wrappedIdentifier, Mapping mapping)

public
HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier, boolean nullMissingEntities, boolean wrappedIdentifier, Mapping mapping, BeanProperty property, NameTransformer unwrapper)

protected

Method Summary

Modifier and TypeMethod and Description
public void
public JsonSerializer<?>
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
)

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 Object
findProxied(HibernateProxy proxy)

Helper method for finding value being proxied, if it is available or if it is to be forced to be loaded.

protected JsonSerializer<Object>
private String

Returns:

Name of the identity property of the specified lazy initializer.
getIdentifierPropertyName
(final LazyInitializer
Lazy initializer to obtain identifier property name from.
init
)

Helper method to retrieve the name of the identifier property of the specified lazy initializer.

public boolean
isEmpty(SerializerProvider provider, HibernateProxy 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.

public void
serialize(HibernateProxy
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.JsonSerializer.serialize.

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

public void
serializeWithType(HibernateProxy
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 JsonSerializer<HibernateProxy>
unwrappingSerializer(final NameTransformer
Name transformation to use to convert between names of unwrapper properties
unwrapper
)

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

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

Inherited from com.fasterxml.jackson.databind.JsonSerializer:
getDelegateehandledTypeisEmptypropertiesreplaceDelegateeusesObjectIdwithFilterIdwithIgnoredProperties

Field Detail

_dynamicSerializersback to summary
protected PropertySerializerMap _dynamicSerializers

For efficient serializer lookup, let's use this; most of the time, there's just one type and one serializer.

_forceLazyLoadingback to summary
protected final boolean _forceLazyLoading
_mappingback to summary
protected final Mapping _mapping
_nullMissingEntitiesback to summary
protected final boolean _nullMissingEntities
_propertyback to summary
protected final BeanProperty _property

Property that has proxy value to handle

_serializeIdentifierback to summary
protected final boolean _serializeIdentifier
_unwrapperback to summary
protected final NameTransformer _unwrapper
_wrappedIdentifierback to summary
protected final boolean _wrappedIdentifier

Constructor Detail

HibernateProxySerializerback to summary
public HibernateProxySerializer(boolean forceLazyLoading)

Deprecated

Annotations
@Deprecated
HibernateProxySerializerback to summary
public HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier)

Deprecated

Annotations
@Deprecated
HibernateProxySerializerback to summary
public HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier, Mapping mapping)

Deprecated

Annotations
@Deprecated
HibernateProxySerializerback to summary
public HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier, boolean nullMissingEntities, Mapping mapping)

Deprecated

Annotations
@Deprecated
HibernateProxySerializerback to summary
public HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier, boolean nullMissingEntities, Mapping mapping, BeanProperty property)

Deprecated

Annotations
@Deprecated
HibernateProxySerializerback to summary
public HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier, boolean nullMissingEntities, boolean wrappedIdentifier, Mapping mapping)
Since
2.12
HibernateProxySerializerback to summary
public HibernateProxySerializer(boolean forceLazyLoading, boolean serializeIdentifier, boolean nullMissingEntities, boolean wrappedIdentifier, Mapping mapping, BeanProperty property, NameTransformer unwrapper)
Since
2.12
HibernateProxySerializerback to summary
protected HibernateProxySerializer(HibernateProxySerializer base, BeanProperty property, NameTransformer unwrapper)
Since
2.12

Method Detail

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

Overrides com.fasterxml.jackson.databind.JsonSerializer.acceptJsonFormatVisitor.

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

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

Default implementation simply calls JsonFormatVisitorWrapper#expectAnyFormat(JavaType).

Parameters
typeHint:JavaType

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

Type of element (entity like property) being visited

Annotations
@Override
createContextualback to summary
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property)

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

Annotations
@Override
findProxiedback to summary
protected Object findProxied(HibernateProxy proxy)

Helper method for finding value being proxied, if it is available or if it is to be forced to be loaded.

findSerializerback to summary
protected JsonSerializer<Object> findSerializer(SerializerProvider provider, Object value) throws IOException
getIdentifierPropertyNameback to summary
private String getIdentifierPropertyName(final LazyInitializer init)

Helper method to retrieve the name of the identifier property of the specified lazy initializer.

Parameters
init:LazyInitializer

Lazy initializer to obtain identifier property name from.

Returns:String

Name of the identity property of the specified lazy initializer.

isEmptyback to summary
public boolean isEmpty(SerializerProvider provider, HibernateProxy 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
serializeback to summary
public void serialize(HibernateProxy value, JsonGenerator g, SerializerProvider provider) throws IOException

Implements abstract com.fasterxml.jackson.databind.JsonSerializer.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:HibernateProxy

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(HibernateProxy 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:HibernateProxy

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 JsonSerializer<HibernateProxy> unwrappingSerializer(final NameTransformer unwrapper)

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

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

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
com.fasterxml.jackson.datatype.hibernate5 back to summary

protected Class HibernateProxySerializer.ProxyReader

extends Object
Class Inheritance
  • java.lang.Object
  • com.fasterxml.jackson.datatype.hibernate5.HibernateProxySerializer.ProxyReader

Inspects a Hibernate proxy to try and determine the name of the identifier property (Hibernate proxies know the getter of the identifier property because it receives special treatment in the invocation handler). Alas, the field storing the method reference is private and has no getter, so we must resort to ugly reflection hacks to read its value ...

Field Summary

Modifier and TypeField and Description
private static final Field

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
pack-priv static String

Returns:

the name of the identifier property, or null if the name could not be determined
getIdentifierPropertyName
(LazyInitializer init)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

getIdentifierMethodFieldback to summary
private static final Field getIdentifierMethodField

Constructor Detail

ProxyReaderback to summary
protected ProxyReader()

Method Detail

getIdentifierPropertyNameback to summary
pack-priv static String getIdentifierPropertyName(LazyInitializer init)
Returns:String

the name of the identifier property, or null if the name could not be determined

com.fasterxml.jackson.datatype.hibernate5 back to summary

protected Class HibernateProxySerializer.ProxySessionReader

extends Object
Class Inheritance
  • java.lang.Object
  • com.fasterxml.jackson.datatype.hibernate5.HibernateProxySerializer.ProxySessionReader

Hibernate 5.2 broke abi compatibility of org.hibernate.proxy.LazyInitializer.getSession() The api contract changed from org.hibernate.proxy.LazyInitializer.getSession()Lorg.hibernate.engine.spi.SessionImplementor; to org.hibernate.proxy.LazyInitializer.getSession()Lorg.hibernate.engine.spi.SharedSessionContractImplementor On hibernate 5.2 the interface SessionImplementor extends SharedSessionContractImplementor. And an instance of org.hibernate.internal.SessionImpl is returned from getSession().

Field Summary

Modifier and TypeField and Description
protected static final Method
lazyInitializerGetSessionMethod

The getSession method must be executed using reflection for compatibility purpose.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
pack-priv static String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lazyInitializerGetSessionMethodback to summary
protected static final Method lazyInitializerGetSessionMethod

The getSession method must be executed using reflection for compatibility purpose. For efficiency keep the method cached.

Constructor Detail

ProxySessionReaderback to summary
protected ProxySessionReader()

Method Detail

getIdentifierPropertyNameback to summary
pack-priv static String getIdentifierPropertyName(LazyInitializer init)