users@jersey.java.net

[Jersey] Re: Jersey + Hibernate + lazyLoad: No serializer for JavassistLazyInitializer

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Fri, 1 Apr 2011 10:50:02 -0700

On Thu, Mar 31, 2011 at 3:28 PM, Peff <peff_at_gmx.at> wrote:
> Hello together,
>
> When Jersey tries to serialize my the lazyloaded parts of my returned class
> it throws the following errorr:
> 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:
> de.**.web.util.ReturnSearch["rideSearch"]->de.**.web.util.RideSearch["user"]->de.**.model.User_$$_javassist_1["handler"])
>
> None of the solutions I found worked:
>
> 1. jackson-module-hibernate
> (https://github.com/FasterXML/jackson-module-hibernate)
> this seems to cover exactly what i am looking for. The instructions to
> register the ObjectMapper are only for Spring and i did not found a
> possibility how to do this in Jersey. Can anybody help me with that?

There are probably better entries in FAQs somewhere, but this:

http://stackoverflow.com/questions/5005668/configure-jersey-jackson-to-not-use-xmlelement-field-annotation-for-json-field-n

at least shows the idea. There isn't anything specific to hibernate
module, from jersey registration perspective, you just need to add
dependency or jar.

Also please note that development of hibernate module is very much
driven by users and usage, so if you can give feedback & help team,
that would be greatly appreciated.
And should help authors find even more time to work on it. :-)
(FWIW, I did not write this module, have just helped make it integrate
nicely -- I am aware of usefulness of things & get good feedback, but
I hope module authors get this too)

Discussions on specific issue may belong more to jackson user list
(since there are RESTeasy/spring/CXF users that may not read jersey
lists), but I assume this is also something of interest to many Jersey
users.

-+ Tatu +-