Jackson JSON Processor
  1. Jackson JSON Processor
  2. JACKSON-224

JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Not A Bug
    • Affects Version/s: 1.4
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Apache Tomcat 6.0.20, Spring 3.0, Hibernate 3.3.2, Sun JDK 6
    • Number of attachments :
      0

      Description

      I'm using the Spring org.springframework.web.servlet.view.json.MappingJacksonJsonView MVC View for the purposes of serializing some domain objects into JSON. I have two domain objects that relate to each other using a @OneToMany relationship. When Spring attempts to use the MappingJacksonJsonView to return one of these objects I receive the following exception:
      Org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.HashMap["prospect"]>com.softrek.dms.domain.Prospect["addresses"]>org.hibernate.collection.PersistentSet[0]>com.softrek.dms.domain.Address["prospect"]>com.softrek.dms.domain.Prospect_$$_javassist_1["hibernateLazyInitializer"])
      at org.codehaus.jackson.map.ser.StdSerializerProvider$1.serialize(StdSerializerProvider.java:55)
      at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
      at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
      at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
      at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
      at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:151)
      at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serialize(ContainerSerializers.java:117)
      at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:218)
      at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:122)
      at org.codehaus.jackson.map.ser.MapSerializer.serializeEntries(MapSerializer.java:131)
      at org.codehaus.jackson.map.ser.MapSerializer.serialize(MapSerializer.java:74)
      at org.codehaus.jackson.map.ser.MapSerializer.serialize(MapSerializer.java:19)
      at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:260)
      at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:212)
      at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:692)
      at org.springframework.web.servlet.view.json.MappingJacksonJsonView.renderMergedOutputModel(MappingJacksonJsonView.java:128)
      at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
      at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:71)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:637)

      I understand the issue is that my domain objects are really proxy objects since I'm using Hibernate, and I realize that within the context of JSON a lazy loaded Set of objects really has no meaning. So, my question is, how can I configure/annotate the domain object such that Jackson will ignore the lazy loaded property when attempting to serialize the object? I believe this might be related to JACKSON-201, but I'm not sure. I tried @JsonIgnore, but it had no effect in relation to solving this issue.

      Thanks for your help.

        Activity

        Hide
        Andre Bickford added a comment -

        I should have mentioned that, obviously, I've told Hibernate to lazy load the @OneToMany relationship.

        Show
        Andre Bickford added a comment - I should have mentioned that, obviously, I've told Hibernate to lazy load the @OneToMany relationship.
        Hide
        Andre Bickford added a comment - - edited

        Ok, I think I figured out the issue here. I had the answer in front of me all along. If you look at the exception it's trying to tell me there's a circular reference:

        java.util.HashMap["prospect"]>com.softrek.dms.domain.Prospect["addresses"]>org.hibernate.collection.PersistentSet[0]>com.softrek.dms.domain.Address["prospect"]>com.softrek.dms.domain.Prospect_$$_javassist_1["hibernateLazyInitializer"])

        I had Prospect linked to Address with @OneToMany and Address linked to Prospect with @ManyToOne. I removed the @ManyToOne annotation from Address to create a uni-directional relationship and Jackson successfully serialized my Prospect object, including the lazy-loaded Addresses thanks to Springs OpenSessionInViewFilter.

        Show
        Andre Bickford added a comment - - edited Ok, I think I figured out the issue here. I had the answer in front of me all along. If you look at the exception it's trying to tell me there's a circular reference: java.util.HashMap ["prospect"] >com.softrek.dms.domain.Prospect ["addresses"] >org.hibernate.collection.PersistentSet [0] >com.softrek.dms.domain.Address ["prospect"] >com.softrek.dms.domain.Prospect_$$_javassist_1 ["hibernateLazyInitializer"] ) I had Prospect linked to Address with @OneToMany and Address linked to Prospect with @ManyToOne. I removed the @ManyToOne annotation from Address to create a uni-directional relationship and Jackson successfully serialized my Prospect object, including the lazy-loaded Addresses thanks to Springs OpenSessionInViewFilter.
        Hide
        Andre Bickford added a comment -

        Resolving issue. Not a bug. I'll post a question to the mailing list to inquire how to exclude the lazy loaded Set from serialization since I may want to do that to reduce network traffic.

        Show
        Andre Bickford added a comment - Resolving issue. Not a bug. I'll post a question to the mailing list to inquire how to exclude the lazy loaded Set from serialization since I may want to do that to reduce network traffic.
        Hide
        Tatu Saloranta added a comment -

        Sounds good. Resolving of back references is tricky – currently there is no way to declaratively handle cyclic references.
        Manually one could add annotations, except that ORM frameworks like Hibernate may add these in generated classes.
        If there are specific cases where these should always be suppressed, those could be added. This is done for some JVM languages and frameworks (like set/get methods for Groovy class metadata).

        As to lazy loading: yes, I would be interested in learning more about use case(s). I am aware that this is an area where better handling would be useful.

        Show
        Tatu Saloranta added a comment - Sounds good. Resolving of back references is tricky – currently there is no way to declaratively handle cyclic references. Manually one could add annotations, except that ORM frameworks like Hibernate may add these in generated classes. If there are specific cases where these should always be suppressed, those could be added. This is done for some JVM languages and frameworks (like set/get methods for Groovy class metadata). As to lazy loading: yes, I would be interested in learning more about use case(s). I am aware that this is an area where better handling would be useful.
        Hide
        Barathwaj added a comment -

        Hi, today i got the same issue using version 1.4.3. I am trying to passon the DTO with the hibernate domain object on it. I didnt evit the domain object yet, and getting the same error as listed above. can you please help me with this issue. I see that its tagged as not a bug, if so what is the way to fix the issue in my project.

        Show
        Barathwaj added a comment - Hi, today i got the same issue using version 1.4.3. I am trying to passon the DTO with the hibernate domain object on it. I didnt evit the domain object yet, and getting the same error as listed above. can you please help me with this issue. I see that its tagged as not a bug, if so what is the way to fix the issue in my project.
        Hide
        Tatu Saloranta added a comment -

        Did you read true changes Andre made? And tried it?

        Show
        Tatu Saloranta added a comment - Did you read true changes Andre made? And tried it?
        Hide
        Tatu Saloranta added a comment -

        The original problem was resolved – for additional hibernate-related problems, please create a new issue so that each entry describes a single problem.

        Show
        Tatu Saloranta added a comment - The original problem was resolved – for additional hibernate-related problems, please create a new issue so that each entry describes a single problem.

          People

          • Assignee:
            Tatu Saloranta
            Reporter:
            Andre Bickford
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: