com.fasterxml.jackson.module.hibernate.HibernateSerializers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-module-hibernate Show documentation
Show all versions of jackson-module-hibernate Show documentation
Add-on module for Jackson (http://jackson.codehaus.org) to support
Hibernate (http://hibernate.org) data types.
package com.fasterxml.jackson.module.hibernate;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.collection.PersistentMap;
import org.hibernate.proxy.HibernateProxy;
import org.codehaus.jackson.map.*;
import org.codehaus.jackson.map.type.CollectionType;
import org.codehaus.jackson.map.type.MapType;
import org.codehaus.jackson.type.JavaType;
import com.fasterxml.jackson.module.hibernate.HibernateModule.Feature;
public class HibernateSerializers extends Serializers.None
{
protected final int _moduleFeatures;
public HibernateSerializers(int features)
{
_moduleFeatures = features;
}
@Override
public JsonSerializer> findSerializer(
SerializationConfig config, JavaType type,
BeanDescription beanDesc, BeanProperty beanProperty )
{
Class> raw = type.getRawClass();
/* Note: PersistentCollection does not implement Collection, so we
* may get some types here...
*/
if (PersistentCollection.class.isAssignableFrom(raw)) {
// TODO: handle iterator types?
}
if (HibernateProxy.class.isAssignableFrom(raw)) {
return new HibernateProxySerializer(beanProperty, isEnabled(Feature.FORCE_LAZY_LOADING));
}
return null;
}
@Override
public JsonSerializer> findCollectionSerializer(SerializationConfig config,
CollectionType type, BeanDescription beanDesc, BeanProperty property,
TypeSerializer elementTypeSerializer, JsonSerializer