You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Benson Margulies <bi...@gmail.com> on 2009/10/14 14:27:01 UTC

JAX-RS versus object references

Starting from hibernate, I seem to have engineered myself into a small
corner.

class Parent {
  int id; // public property fcns available
};

class Child {
  int id;
 Parent parent;
};

What I want in the JSON is the parent's ID, not an entire dump of the
parent. Using jackson, there might be an annotation to fix this, but since
the java is generated by hibernate, and the doc on this area in hibernate is
awful, I don't much want to go there. There's nothing generic to JAX-RS for
dealing with this, is there?

RE: JAX-RS versus object references

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi Benson,

Interesting... but sounds quite complicated.
As a user I'd just like to tell my runtime :

Parent class can only have its 'id' field serialized, possibly during a
given query only. Or may be : that and that field in Parent has to be
ignored.

That is it.

The feature I'm hoping to contribute eventually will let users tell the
runtime to drop the elements but it can be inefficient for cases like
Parent as it won't prevent the JAXB runtime from attempting to write
every other field Parent might have. 

The dynamic proxy solution seems like the right one, possibly ASM-based,
so that JAXB can be tricked into believing all Parent fields except id
are @XmlTransient.

By the way, XSLTJaxbProvider can produce JSON too, just register a
stylesheet for application/json - but again it might/can be inefficient
for this specific case. 

Cheers, Sergey

-----Original Message-----
From: Benson Margulies [mailto:bimargulies@gmail.com] 
Sent: 14 October 2009 13:47
To: users@cxf.apache.org
Subject: Re: JAX-RS versus object references

It's comforting to have company.

Reading your email, it seems as if what I really need is to use Tatu's
mechanisms in Jackson to serialize a Parent reference as the Parent's
ID. I
could do that by coping with hibernate <meta> tags, or by turning off
hibernate Java generation, checking in the classes, and just adding his
annotations. Or I could find out if his JAX-RS providers can be spoken
to
about their ObjectMapper objects, to which I think I could give orders
for
this purpose.

Just dropping names won't help me. I need to map back and forth to Ids.
On
the serialization side, one would think that a jaxb customization would
be
easy, but coming back the other way I'd need to map the integer ID to
the
reference, if I don't want hibernate databasing my pants off, I don't
know
what I need.

For now I've eliminated the <many-to-one/> items from hibernate, and
made
the classes just store the integer ids, since I don't have any really
strong
need for the object references at all.

On Wed, Oct 14, 2009 at 8:37 AM, Sergey Beryozkin
<sb...@progress.com>wrote:

> Hi Benson
>
> It appears to be quite a common query.
> I think, ultimately, JBoss JAXB introductions could be of help but
> apprently they don't support dynamic proxies for 'XmlTransient.
> What I'm working upon in the background is for letting users to
specify, by
> listing a list of names (possibly fully qualified) which have to be
dropped,
> as a property on (default) JAXB/JSOn providers.
> So the intermediate option is to register a custom JSONProvider which
> extends the one we ship and which overrides
>
> getStreamWriter() method, which will return a custom writer configured
to
> drop everything in Parent but its id.
>
> I'm not sure how efficient it can be with hibernate, that is I'm not
sure
> if blocking at the XMlStreamWriter level will prevent JAXB/hibernate
from
> executing futile db queries under the hood
> Give it a try though please, I'd be interested to know if it helps
>
> Sergey
>
>
>
>  Starting from hibernate, I seem to have engineered myself into a
small
>> corner.
>>
>> class Parent {
>>  int id; // public property fcns available
>> };
>>
>> class Child {
>>  int id;
>> Parent parent;
>> };
>>
>> What I want in the JSON is the parent's ID, not an entire dump of the
>> parent. Using jackson, there might be an annotation to fix this, but
since
>> the java is generated by hibernate, and the doc on this area in
hibernate
>> is
>> awful, I don't much want to go there. There's nothing generic to
JAX-RS
>> for
>> dealing with this, is there?
>>
>>
>

Re: JAX-RS versus object references

Posted by Benson Margulies <bi...@gmail.com>.
It's comforting to have company.

Reading your email, it seems as if what I really need is to use Tatu's
mechanisms in Jackson to serialize a Parent reference as the Parent's ID. I
could do that by coping with hibernate <meta> tags, or by turning off
hibernate Java generation, checking in the classes, and just adding his
annotations. Or I could find out if his JAX-RS providers can be spoken to
about their ObjectMapper objects, to which I think I could give orders for
this purpose.

Just dropping names won't help me. I need to map back and forth to Ids. On
the serialization side, one would think that a jaxb customization would be
easy, but coming back the other way I'd need to map the integer ID to the
reference, if I don't want hibernate databasing my pants off, I don't know
what I need.

For now I've eliminated the <many-to-one/> items from hibernate, and made
the classes just store the integer ids, since I don't have any really strong
need for the object references at all.

On Wed, Oct 14, 2009 at 8:37 AM, Sergey Beryozkin <sb...@progress.com>wrote:

> Hi Benson
>
> It appears to be quite a common query.
> I think, ultimately, JBoss JAXB introductions could be of help but
> apprently they don't support dynamic proxies for 'XmlTransient.
> What I'm working upon in the background is for letting users to specify, by
> listing a list of names (possibly fully qualified) which have to be dropped,
> as a property on (default) JAXB/JSOn providers.
> So the intermediate option is to register a custom JSONProvider which
> extends the one we ship and which overrides
>
> getStreamWriter() method, which will return a custom writer configured to
> drop everything in Parent but its id.
>
> I'm not sure how efficient it can be with hibernate, that is I'm not sure
> if blocking at the XMlStreamWriter level will prevent JAXB/hibernate from
> executing futile db queries under the hood
> Give it a try though please, I'd be interested to know if it helps
>
> Sergey
>
>
>
>  Starting from hibernate, I seem to have engineered myself into a small
>> corner.
>>
>> class Parent {
>>  int id; // public property fcns available
>> };
>>
>> class Child {
>>  int id;
>> Parent parent;
>> };
>>
>> What I want in the JSON is the parent's ID, not an entire dump of the
>> parent. Using jackson, there might be an annotation to fix this, but since
>> the java is generated by hibernate, and the doc on this area in hibernate
>> is
>> awful, I don't much want to go there. There's nothing generic to JAX-RS
>> for
>> dealing with this, is there?
>>
>>
>

Re: JAX-RS versus object references

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi Benson

It appears to be quite a common query.
I think, ultimately, JBoss JAXB introductions could be of help but apprently they don't support dynamic proxies for 'XmlTransient.
What I'm working upon in the background is for letting users to specify, by listing a list of names (possibly fully qualified) which 
have to be dropped, as a property on (default) JAXB/JSOn providers.
So the intermediate option is to register a custom JSONProvider which extends the one we ship and which overrides

getStreamWriter() method, which will return a custom writer configured to drop everything in Parent but its id.

I'm not sure how efficient it can be with hibernate, that is I'm not sure if blocking at the XMlStreamWriter level will prevent 
JAXB/hibernate from executing futile db queries under the hood
Give it a try though please, I'd be interested to know if it helps

Sergey


> Starting from hibernate, I seem to have engineered myself into a small
> corner.
>
> class Parent {
>  int id; // public property fcns available
> };
>
> class Child {
>  int id;
> Parent parent;
> };
>
> What I want in the JSON is the parent's ID, not an entire dump of the
> parent. Using jackson, there might be an annotation to fix this, but since
> the java is generated by hibernate, and the doc on this area in hibernate is
> awful, I don't much want to go there. There's nothing generic to JAX-RS for
> dealing with this, is there?
>