Class HibernateProxySerializer

  • All Implemented Interfaces:
    com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable, com.fasterxml.jackson.databind.ser.ContextualSerializer

    public class HibernateProxySerializer
    extends com.fasterxml.jackson.databind.JsonSerializer<org.hibernate.proxy.HibernateProxy>
    implements com.fasterxml.jackson.databind.ser.ContextualSerializer
    Serializer to use for values proxied using 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 Class Summary

      Nested Classes 
      Modifier and Type Class 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.
      • Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer

        com.fasterxml.jackson.databind.JsonSerializer.None
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap _dynamicSerializers
      For efficient serializer lookup, let's use this; most of the time, there's just one type and one serializer.
      protected boolean _forceLazyLoading  
      protected org.hibernate.engine.spi.Mapping _mapping  
      protected boolean _nullMissingEntities  
      protected com.fasterxml.jackson.databind.BeanProperty _property
      Property that has proxy value to handle
      protected boolean _serializeIdentifier  
      protected com.fasterxml.jackson.databind.util.NameTransformer _unwrapper  
      protected boolean _wrappedIdentifier  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        HibernateProxySerializer​(boolean forceLazyLoading)
      Deprecated.
        HibernateProxySerializer​(boolean forceLazyLoading, boolean serializeIdentifier)
      Deprecated.
        HibernateProxySerializer​(boolean forceLazyLoading, boolean serializeIdentifier, boolean nullMissingEntities, boolean wrappedIdentifier, org.hibernate.engine.spi.Mapping mapping)  
        HibernateProxySerializer​(boolean forceLazyLoading, boolean serializeIdentifier, boolean nullMissingEntities, boolean wrappedIdentifier, org.hibernate.engine.spi.Mapping mapping, com.fasterxml.jackson.databind.BeanProperty property, com.fasterxml.jackson.databind.util.NameTransformer unwrapper)  
        HibernateProxySerializer​(boolean forceLazyLoading, boolean serializeIdentifier, boolean nullMissingEntities, org.hibernate.engine.spi.Mapping mapping)
      Deprecated.
        HibernateProxySerializer​(boolean forceLazyLoading, boolean serializeIdentifier, boolean nullMissingEntities, org.hibernate.engine.spi.Mapping mapping, com.fasterxml.jackson.databind.BeanProperty property)
      Deprecated.
        HibernateProxySerializer​(boolean forceLazyLoading, boolean serializeIdentifier, org.hibernate.engine.spi.Mapping mapping)
      Deprecated.
      protected HibernateProxySerializer​(HibernateProxySerializer base, com.fasterxml.jackson.databind.BeanProperty property, com.fasterxml.jackson.databind.util.NameTransformer unwrapper)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void acceptJsonFormatVisitor​(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper visitor, com.fasterxml.jackson.databind.JavaType typeHint)  
      com.fasterxml.jackson.databind.JsonSerializer<?> createContextual​(com.fasterxml.jackson.databind.SerializerProvider prov, com.fasterxml.jackson.databind.BeanProperty property)  
      protected Object findProxied​(org.hibernate.proxy.HibernateProxy proxy)
      Helper method for finding value being proxied, if it is available or if it is to be forced to be loaded.
      protected com.fasterxml.jackson.databind.JsonSerializer<Object> findSerializer​(com.fasterxml.jackson.databind.SerializerProvider provider, Object value)  
      boolean isEmpty​(com.fasterxml.jackson.databind.SerializerProvider provider, org.hibernate.proxy.HibernateProxy value)  
      boolean isUnwrappingSerializer()  
      void serialize​(org.hibernate.proxy.HibernateProxy value, com.fasterxml.jackson.core.JsonGenerator g, com.fasterxml.jackson.databind.SerializerProvider provider)  
      void serializeWithType​(org.hibernate.proxy.HibernateProxy value, com.fasterxml.jackson.core.JsonGenerator g, com.fasterxml.jackson.databind.SerializerProvider provider, com.fasterxml.jackson.databind.jsontype.TypeSerializer typeSer)  
      com.fasterxml.jackson.databind.JsonSerializer<org.hibernate.proxy.HibernateProxy> unwrappingSerializer​(com.fasterxml.jackson.databind.util.NameTransformer unwrapper)  
      • Methods inherited from class com.fasterxml.jackson.databind.JsonSerializer

        getDelegatee, handledType, isEmpty, properties, replaceDelegatee, usesObjectId, withFilterId, withIgnoredProperties
    • Field Detail

      • _property

        protected final com.fasterxml.jackson.databind.BeanProperty _property
        Property that has proxy value to handle
      • _forceLazyLoading

        protected final boolean _forceLazyLoading
      • _serializeIdentifier

        protected final boolean _serializeIdentifier
      • _nullMissingEntities

        protected final boolean _nullMissingEntities
      • _wrappedIdentifier

        protected final boolean _wrappedIdentifier
      • _mapping

        protected final org.hibernate.engine.spi.Mapping _mapping
      • _unwrapper

        protected final com.fasterxml.jackson.databind.util.NameTransformer _unwrapper
      • _dynamicSerializers

        protected com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap _dynamicSerializers
        For efficient serializer lookup, let's use this; most of the time, there's just one type and one serializer.
    • Constructor Detail

      • HibernateProxySerializer

        @Deprecated
        public HibernateProxySerializer​(boolean forceLazyLoading)
        Deprecated.
      • HibernateProxySerializer

        @Deprecated
        public HibernateProxySerializer​(boolean forceLazyLoading,
                                        boolean serializeIdentifier)
        Deprecated.
      • HibernateProxySerializer

        @Deprecated
        public HibernateProxySerializer​(boolean forceLazyLoading,
                                        boolean serializeIdentifier,
                                        org.hibernate.engine.spi.Mapping mapping)
        Deprecated.
      • HibernateProxySerializer

        @Deprecated
        public HibernateProxySerializer​(boolean forceLazyLoading,
                                        boolean serializeIdentifier,
                                        boolean nullMissingEntities,
                                        org.hibernate.engine.spi.Mapping mapping)
        Deprecated.
      • HibernateProxySerializer

        @Deprecated
        public HibernateProxySerializer​(boolean forceLazyLoading,
                                        boolean serializeIdentifier,
                                        boolean nullMissingEntities,
                                        org.hibernate.engine.spi.Mapping mapping,
                                        com.fasterxml.jackson.databind.BeanProperty property)
        Deprecated.
      • HibernateProxySerializer

        public HibernateProxySerializer​(boolean forceLazyLoading,
                                        boolean serializeIdentifier,
                                        boolean nullMissingEntities,
                                        boolean wrappedIdentifier,
                                        org.hibernate.engine.spi.Mapping mapping)
        Since:
        2.12
      • HibernateProxySerializer

        public HibernateProxySerializer​(boolean forceLazyLoading,
                                        boolean serializeIdentifier,
                                        boolean nullMissingEntities,
                                        boolean wrappedIdentifier,
                                        org.hibernate.engine.spi.Mapping mapping,
                                        com.fasterxml.jackson.databind.BeanProperty property,
                                        com.fasterxml.jackson.databind.util.NameTransformer unwrapper)
        Since:
        2.12
      • HibernateProxySerializer

        protected HibernateProxySerializer​(HibernateProxySerializer base,
                                           com.fasterxml.jackson.databind.BeanProperty property,
                                           com.fasterxml.jackson.databind.util.NameTransformer unwrapper)
        Since:
        2.12
    • Method Detail

      • createContextual

        public com.fasterxml.jackson.databind.JsonSerializer<?> createContextual​(com.fasterxml.jackson.databind.SerializerProvider prov,
                                                                                 com.fasterxml.jackson.databind.BeanProperty property)
        Specified by:
        createContextual in interface com.fasterxml.jackson.databind.ser.ContextualSerializer
      • unwrappingSerializer

        public com.fasterxml.jackson.databind.JsonSerializer<org.hibernate.proxy.HibernateProxy> unwrappingSerializer​(com.fasterxml.jackson.databind.util.NameTransformer unwrapper)
        Overrides:
        unwrappingSerializer in class com.fasterxml.jackson.databind.JsonSerializer<org.hibernate.proxy.HibernateProxy>
      • isUnwrappingSerializer

        public boolean isUnwrappingSerializer()
        Overrides:
        isUnwrappingSerializer in class com.fasterxml.jackson.databind.JsonSerializer<org.hibernate.proxy.HibernateProxy>
      • isEmpty

        public boolean isEmpty​(com.fasterxml.jackson.databind.SerializerProvider provider,
                               org.hibernate.proxy.HibernateProxy value)
        Overrides:
        isEmpty in class com.fasterxml.jackson.databind.JsonSerializer<org.hibernate.proxy.HibernateProxy>
      • serialize

        public void serialize​(org.hibernate.proxy.HibernateProxy value,
                              com.fasterxml.jackson.core.JsonGenerator g,
                              com.fasterxml.jackson.databind.SerializerProvider provider)
                       throws IOException
        Specified by:
        serialize in class com.fasterxml.jackson.databind.JsonSerializer<org.hibernate.proxy.HibernateProxy>
        Throws:
        IOException
      • serializeWithType

        public void serializeWithType​(org.hibernate.proxy.HibernateProxy value,
                                      com.fasterxml.jackson.core.JsonGenerator g,
                                      com.fasterxml.jackson.databind.SerializerProvider provider,
                                      com.fasterxml.jackson.databind.jsontype.TypeSerializer typeSer)
                               throws IOException
        Overrides:
        serializeWithType in class com.fasterxml.jackson.databind.JsonSerializer<org.hibernate.proxy.HibernateProxy>
        Throws:
        IOException
      • acceptJsonFormatVisitor

        public void acceptJsonFormatVisitor​(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper visitor,
                                            com.fasterxml.jackson.databind.JavaType typeHint)
                                     throws com.fasterxml.jackson.databind.JsonMappingException
        Specified by:
        acceptJsonFormatVisitor in interface com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable
        Overrides:
        acceptJsonFormatVisitor in class com.fasterxml.jackson.databind.JsonSerializer<org.hibernate.proxy.HibernateProxy>
        Throws:
        com.fasterxml.jackson.databind.JsonMappingException
      • findSerializer

        protected com.fasterxml.jackson.databind.JsonSerializer<Object> findSerializer​(com.fasterxml.jackson.databind.SerializerProvider provider,
                                                                                       Object value)
                                                                                throws IOException
        Throws:
        IOException
      • findProxied

        protected Object findProxied​(org.hibernate.proxy.HibernateProxy proxy)
        Helper method for finding value being proxied, if it is available or if it is to be forced to be loaded.