tags:

views:

60

answers:

4

Hey guys,

I am looking for a JSON library that supports defining the serialization depth. Ideally I would like a library that handles all primitive types and java.lang and the rest will be sent to a custom handler. In my case the custom handler should generate a Link object with URL and class of the element (for my REST API).

Here an example:

Person : String name,  Car car

Would be serialized to

{
“name”:”Peter”, 
Link : {“class”:”my.company.Car”, “url”:”http://www.mycompany/myapp/Car/5”}
}

Any ideas which library I could use (and enhance)? Kind regards,

Daniel

+3  A: 

Check out http://code.google.com/p/google-gson/

toomasr
I need to define the serialization depth (the last time I looked a gson that was not possible). Futhermore I want to register a handler for all non primitive types and non java.* types.
DAniel
A: 

You want to have a look at Jackson.

AS you can see you can use simple and complex data-binding rules, and there's a streaming API which will allow you to limit the exploration's depth.

haylem
A: 

If GSON does not fit your needs, I recommend JsonMarshaller. It is highly configurable and customizable yet strives to be simple. It also has a very active user and developer community.

Jacob Tomaw
A: 

I am not sure whether you want actual control for serialization depth (as mentioned) or not -- your explanation rather suggest you want to be able to add custom serializers. Now: if you really need limits (like only shallow copy), you could check out FlexJson, which supposedly has explicit control over serialization depth.

Otherwise, Jackson and GSON at least have full bean serialization as well as allowing custom serializers.

StaxMan