You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by "Kuhns, John" <jk...@AimNTLS.com> on 2010/05/20 16:10:59 UTC

JSON serialization

I am looking for the best method of serializing/de-serializing CayenneDataObjects as JSON. I've written my own class for now, but am interested in hearing about a good method to use either XStream, Jackson or some other library.

John Kuhns


RE: JSON serialization

Posted by "Kuhns, John" <jk...@AimNTLS.com>.
Thanks for the response. I've got the relations part worked out for myself, two int values, parentLevels and childrenLevels, restrict how far to go up/down the relationships. The xml serialization is a little too verbose for me, plus I want to use JSON in the browser.

-----Original Message-----
From: Juergen Saar [mailto:juergen@jsaar.org] 
Sent: Thursday, May 20, 2010 10:38 AM
To: user@cayenne.apache.org
Subject: Re: JSON serialization

Years ago we implermented a serialization into xml ... if not only
attributes, but also relations are serialized, you run into deep trouble ...
we stopped this experiment ...

2010/5/20 Kuhns, John <jk...@aimntls.com>

> I am looking for the best method of serializing/de-serializing
> CayenneDataObjects as JSON. I've written my own class for now, but am
> interested in hearing about a good method to use either XStream, Jackson or
> some other library.
>
> John Kuhns
>
>

Re: JSON serialization

Posted by Andrus Adamchik <an...@objectstyle.org>.
Yes, if you do it uncontrolled, it can become a problem. I started a  
prototype of a smarter serialization framework (based on XStream BTW)  
to solve this exact problem:

  https://svn.apache.org/repos/asf/cayenne/sandbox/cayenne- 
serialization/

The main idea is to define a subgraph of the model to serialize and  
let Cayenne/XStream do the work. In a way it is similar to how  
prefetches are specified - a bunch of path's from the root entity:

Subgraph<Table2> subgraph = new Subgraph<Table2>(Table2.class,  
context.getEntityResolver());
subgraph.addClonePath(Table2.TABLE1_PROPERTY);

XStreamSerializer serializer = new XStreamSerializer();
serializer.serialize(object, subgraph, out);

The prototype has a few unresolved issues and I currently have no time  
to deal with them, but the idea looks solid.

Andrus


On May 20, 2010, at 5:38 PM, Juergen Saar wrote:

> Years ago we implermented a serialization into xml ... if not only
> attributes, but also relations are serialized, you run into deep  
> trouble ...
> we stopped this experiment ...
>
> 2010/5/20 Kuhns, John <jk...@aimntls.com>
>
>> I am looking for the best method of serializing/de-serializing
>> CayenneDataObjects as JSON. I've written my own class for now, but am
>> interested in hearing about a good method to use either XStream,  
>> Jackson or
>> some other library.
>>
>> John Kuhns
>>
>>


Re: JSON serialization

Posted by Juergen Saar <ju...@jsaar.org>.
Years ago we implermented a serialization into xml ... if not only
attributes, but also relations are serialized, you run into deep trouble ...
we stopped this experiment ...

2010/5/20 Kuhns, John <jk...@aimntls.com>

> I am looking for the best method of serializing/de-serializing
> CayenneDataObjects as JSON. I've written my own class for now, but am
> interested in hearing about a good method to use either XStream, Jackson or
> some other library.
>
> John Kuhns
>
>