users@jersey.java.net

[Jersey] Re: JSON serialization question

From: Phillip Ross <phillip.w.g.ross_at_gmail.com>
Date: Sat, 17 Jan 2015 00:44:52 -0500

Laird... I seem to recall getting server 500s w/ message body writer
traces that I tracked down to responses that contained entities that
were also JPA entities with bidirectional relationships within the
graph. I remember this annoying me because it was difficult to track
down the problem with such generic error messages.

I don't think the problem that I bumped into being an issue related to
JPA entities specifically, but it was basically the bidirectionally
and Moxy, being a JAXB implementation, needed some JAXB annotations to
handle the bidirectionality.

The server 500s with generic message body writer errors could maybe be
any internal exception leakage, but if you think you're having the
same problem as I did, I'd be happy to share more information about
the solution I employed.

Take care and hang in there ;)
- Phillip

On Fri, Jan 16, 2015 at 11:57 PM, Laird Nelson <ljnelson_at_gmail.com> wrote:
> Section 4.3 of the JAX-RS 2.0 specification reads (in part):
>
> 4.3. Auto-Discoverable Features
>
> [...] For a few Jersey provided modules however there is no need to
> explicitly register their extension Features as these are discovered and
> registered in the Configuration (on client/server) automatically by Jersey
> runtime whenever the modules implementing these features are present on the
> classpath of the deployed JAX-RS application. The modules that are
> automatically discovered include:
>
> JSON binding feature from jersey-media-moxy
> jersey-media-json-processing
>
>
> I have a war file that does not supply any JSON serialization classes or
> libraries of its own (no Jackson, no Moxy, no MessageBodyWriters, etc.).
> Some of my resource classes served up by that application serve entities, in
> turn, of media type application/json. Ordinary stuff.
>
> My war file contains no servlet information—just an Application subclass
> that does not override any methods—and is not tied to Jersey in any way,
> just to a JAX-RS runtime.
>
> I am getting a 500 error from Jersey v2.10 as shipped with Glassfish 4.1
> (and the error is hidden—but that's another story) that indicates that there
> is no MessageBodyWriter that can serialize my entity. Isn't Moxy, at least,
> present by default in the Glassfish classpath (see
> modules/jersey-media-moxy.jar, though I'm not too familiar with exactly how
> those modules are added to the classpath)?
>
> My interpretation of the above section is that in Glassfish 4.1 Moxy at
> least should be active and attempting to serialize my entity. Is that
> correct? If so, I'll try to put together a test case.
>
> (Disclaimer in case it matters in some way: I work for Oracle, but not on
> Jersey or JAX-RS.)
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson