General J2EE: JSON solution advice needed
Ronald, I use Stringtree JSON ( http://www.stringtree.org/stringtree-json.html ) as my general-purpose Java JSON reader/writer. It's not exactly what you have described, but the code is small enough and simple enough that it seems a good base to start from. If you haven't already found it, there is a list of JSON implementations at the bottom of the page at http://json.org/ which links to several Java implementations including Stringtree JSON. As an aside, You don't really make clear in your original post how set-in-stone your particular usage of JSON might be. I have found over the course of several projects that attempting to convert domain objects directly to/from any external representation (be it JSON, XML, or some binary or custom format) is usually a step too far. Inevitably the conversion code becomes bogged down in special case-processing and soon becomes brittle and proprietary. A more robust solution might be to use a "soft" layer (such as Maps and Lists of Objects) between your "hard" domain objects and the equally "hard" external representation. For example: To send data domain objects -> special processing (in your case omitting and/or renaming fields etc.) -> Map of Objects/Lists/Maps etc. -> standard and simple JSON serializer -> external JSON text To recieve data external JSON text -> standard and simple JSON deserializer -> Map of Objects/Lists/Maps etc.-> special processing (in your case updating changed fields etc.) -> domain objects With this technique, the processing is nicely separated and maintainable. If you use Spring or any other injection approach, the conversion strategy can easily be configured on deployment or at run-time. As a benefit, if you change your mind and choose a different external format (XML, for example), only the serialization needs to be swapped out; the special processing remains unchanged. If this seems like an interesting approach and you would like any more detailed discussion, please feel free to connect with me on LinkedIn and/or contact me direct. Frank. http://blog.punchbarrel.com/
Hi Ronald. One question regarding Jackson: did you try asking your question (wrt Cglib) on the user list? One problem (http://jira.codehaus.org/browse/JACKSON-53) regarding Cglib was resolved earlier, and there is good chance that if there are remaining problems, they could be addressed. But that can only be done if problems are reported. Other than that, like other poster suggested, about all JSON packages allow you to work with "untyped" objects (Maps, Lists); including StringTree, json-lib, json-utils, stringtree, Jackson etc. etc.