0

I am working on glashfish jersey rest services with codehus-Jackson for json data. But i am getting Hibernate lazy initialization exception for that i have added the lazy=false for all child classes. But it was giving infinite recursion error. So i have added JsonIgnore on reverse mapped properties. But it is not detecting. My configuration as follows.

<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.koderzlab.lawman;org.codehaus.jackson.jaxrs</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

My stack trace is as follows

at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:189)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:430)
    at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:175)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142)
    at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serializeContents(ContainerSerializers.java:442)
    at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serializeContents(ContainerSerializers.java:383)
    at org.codehaus.jackson.map.ser.ContainerSerializers$AsArraySerializer.serialize(ContainerSerializers.java:142)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:430)
    at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:175)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:430)
    at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:175)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142)
    at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serializeContents(ContainerSerializers.java:442)
    at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serializeContents(ContainerSerializers.java:383)
unwichtich
  • 13,712
  • 4
  • 53
  • 66
Shashi Dk
  • 174
  • 2
  • 15

2 Answers2

0

Although your Hibernate problem may not get solved by this, it looks like your are scanning the wrong package name for Jackson classes.

For Jackson 2.x, which is normally used with Jersey 2.x, you need to scan in the package com.fasterxml.jackson.jaxrs instead of org.codehaus.jackson.jaxrs.

Change the part in your web.xml to the following:

<init-param>
    <param-name>jersey.config.server.provider.packages</param-name>
    <param-value>com.koderzlab.lawman;com.fasterxml.jackson.jaxrs</param-value>
</init-param>

See also:

Community
  • 1
  • 1
unwichtich
  • 13,712
  • 4
  • 53
  • 66
  • Just an FYI, Jersey has a module [jersey-media-json-jackson1](https://jersey.java.net/documentation/latest/media.html#json.jackson) which uses the codehaus Jackson. In which case, the OP config would be correct :-) – Paul Samsotha Feb 26 '15 at 11:36
  • Hi @unwichtich thanks for your response. Actually i have tried it but it didn't work and com.koderzlab.lawman is my base package after src folder. – Shashi Dk Feb 26 '15 at 12:02
  • Then maybe you should update your question with the exception stacktrace. – unwichtich Feb 26 '15 at 13:01
  • Hi @unwichtich please find the stack trace for my issue that i have mentioned . please help me to resolve this issue – Shashi Dk Mar 04 '15 at 05:10
0

Just i have added the codehusjackson 1.9.2 jars now it is recognizing @JsonBack reference. But on each pojo class we need to add
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})

Shashi Dk
  • 174
  • 2
  • 15