I currently use JAXB for a project i’m working on and looking to convert my libraries archived xml to archived json, To act in my project. I figured I would use Jettison as it seems it would be easier to implement since it actually works with JAXB; however, looking at Older benchmarks in which Jettison was not included I have found Kryo produces smaller files and Serialized and DeSerialized quicker than some alternatives.
Can anyone inform me of the key difference or otherwise how Jettison stacks up to Kryo, especially for future projects such as android applications.
EDIT:
I guess i’m looking for what produces smaller files and operates faster. Human readability can be sacrificed since I don’t plan on reading the files only processing them
Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.
Since you already have established JAXB mappings and are converting XML to JSON, you may be interested in EclipseLink JAXB (MOXy) which offers both object-to-XML and object-to-JSON mapping using the same JAXB metadata.
Customer
Below is a sample model with JAXB annotations.
jaxb.properties
To use MOXy as your JAXB provider you need to include a file called
jaxb.propertiesin the same package as your domain model with the following entry (see: http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html).input.xml
Demo
The following demo code will populate the objects from XML and then output JSON. Note how there are no compile time dependencies on MOXy.
JSON Ouput
Below is the output from running the demo code.
A few things to note about the output:
idfield is a numeric type it was marshalled to JSON without quotes.idfield was mapped with@XmlAttributethere are no special indication of this in the JSON message.emailproperty had aListof size one, this is properly represented in the JSON output.xsi:nilmechanism was used to specify that thelastNamefield had anullvalue, this has been translated to the proper null representation in the JSON output.For More Information