Skip navigation.
Arch2Arch Tab BEA.com

Article: An Introduction to JSON
Subject:  Other options for generating JSON data to avoid a copy
Date:  2007-04-19 10:13:12
From:  jsnyders

I think the copying of objects to JSONArray/JSONObject just to serialize them is wasteful both in time and space. I don't have data to say just how wasteful.

There are 3 options:
1) In a web app the value objects are often copies of some other underlying data (like from a database) so just replace them with JSONObject and skip one copy
2) Write custom serialization code. The effort to do this is about the same as the example above that copies the address objects to JSON objects. A code gen technique would work well here.
3) Use a one size fits all serializer. I assume that the XStream thing is in this category. The drawback here is that it will use reflection

I have used option 1 in practice. My guess is that options 2 or 1 would perform the best.