开发者

JSON "flat" serialization with Java

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


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


You want to have a look at Jackson.

  • Jackson Wiki
  • Jackson in 5 Minutes

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜