A program, sooner or later, must persist or exchange data. In java data is stored in memory into objects. Objects are structure with data and behaviour. Java object can be directly stored or send over the network using serialization and rmi. But serialization uses a binary format and work only with java. This is not the best way to exchange data. For interoperability pourposes, other formats are used to exchange data. Two common format are xml and json. Both are text format. Text formats are easier, because are human readable.
Java does not have out-of-the-box conversion of object into xml or json. Writing code to convert object into data (and back) is very boring. There is nothing creative in this repetitive task. Librariers are developed for this pourpose. Due to static types in java, special api must be used to browse object to extract data: reflection or code enhancement/generation. Reflection can manipulate object at runtime dinamically. Reflection is quite slow (about 10 time slower compared to "normal" code). Reflection isn't available in GWT. Code generation/enhancement is another option. In this case java code is generated (or existing bytecode modified) to convert objects. In this case the java beans that maps are generated. Because code is generated, can't be modified by the programmer (he lost the changes in the next re-generation).
Another think to consider are the mapping rules. The framework must know how to translate java objects graph into xml or json structures. For this pourpose frameworks uses configuration files (most xml) or java annotations.
I am not happy with configuration files or annotations. If the mapping does not match the default rule, you must configure or annotate each class / each attribute. Suppose for example the framework map attributes uppercase and you need lowecase, sometimes you CAN'T configure only one default property, but you must configure each class/attribute. How easy is to make a tip error? Some framework require that you annotate each class that must be converted. Very annoying! Annotations are framework specific, in case you change framework, you must replace annotations in source code.
I like to have a java binding framework with the following requirements:
  • Does not uses reflection: I need a fast solution that work with gwt too. Because the only alternative in this case is code generation, I need that the code generated is source java code (not bytecode enhancement). Source code works with gwt and is more easy to debug.
  • The generated java source code must not be the beans and the binding code, but ONLY the binding code over EXISTING objects. This way the re-generation will overwrite the binding code but let me change the beans and add business logic without problems.
  • The mapping rules are not specified by annotation or config file for each class. Java classes must be untouched, they don't must hold any mapping informations. A default configuration file define the set of classes and default rules that are applied to all class in the set.
  • A general java object set is a graph while xml and json are tree structures. The framework must support object graph (object identities).
  • Java classes uses inheritance. I can save a dog into an animal object. I need that event sub-classes are converted properly.
I haven't found such a java binding framework, then I have created myself! Do you need something like this too?
DM Project
I am the creator/owner of this free/open source projects:
converting data to java objects and vice versa
DM Web Framework
HTML5 interactive web pages
DM JsJvm
small and smart javascript jvm