users@jersey.java.net

[Jersey] jersey-server-linking chases object references in entities

From: Daniel Larsson <daniel.j.larsson_at_gmail.com>
Date: Wed, 6 Jul 2011 15:39:49 +0200

Tried out jersey-server-linking a bit, and noticed the RefProcessor
recursively chases object references in the entity object, trying to find
@Link annotations. This is causing a bit of a problem for me. Part of the
returned entity is a JPA entity bean, where I've filtered out certain
properties (don't want to send the transitive closure of the object graph
back as JSON, so I'm typically marking object references with @XmlTransient,
and adding properties returning URIs instead, which are included in the JSON
output). But since the JPA entity is part of the Jersey Response entity,
*every* object reference is chased, causing tons of SQL queries to be
performed, to bring in those objects into memory. Not fun. I couldn't see a
way to influence the reference chasing, is this correct? In other words, I
will need to make a proxy for the JPA entity, only exposing the subset of
the JPA bean properties I actually want to serialize, yes?

Thanks in advance,

Daniel Larsson