| Article: |
The State of JAXB: Availability, Suitability, Analysis, and Architecture | |
| Subject: | Looking for POJO serialization | |
| Date: | 2004-05-07 17:39:29 | |
| From: | johnlindwall | |
|
I've been evaluation various Java <-> XML solutions as a way to serialize existing java domain objects (containing data AND behavior) to/from XML.
|
||
Showing messages 1 through 3 of 3.
-
Looking for POJO serialization
2004-05-10 07:40:34 bazzargh [View]
-
Looking for POJO serialization
2004-05-10 12:43:19 satyak [View]
John,
Thanks for a very informative post. This is the beauty and bane of java at the moment. Very inventive solutions are there all around but difficult to standardize on in an IT environment. Unfortunately at the start of the article I haven't looked into XMLEncoder. As some posters are suggesting it may not be a bad idea to look into it for simple xml documents and cases where no one is yelling out loud for an XSD. For cases where XSD is available I felt JAXB is very good over all. I have looked at Castor only briefly as JAXB is part of the standard. Unfortunately I can't answer convincingly which of the alternatives are better where XSD is not available or cumbersome to maintain. Looks like you are on the right track to look at the right tools. Perhaps you can publish your results :-) and your experiences.
Thanks
Satya
-
Looking for POJO serialization
2004-05-11 10:45:55 Michaelok [View]



http://jcp.org/en/jsr/detail?id=031
"The [...] facility compiles an XML schema into one or more Java classes. These automatically-generated classes handle the translation between XML documents that follow the schema and interrelated instances of the derived classes. They also ensure that the constraints expressed in the schema are maintained as instances of the classes are manipulated."
ie its not a generic XML serialization tool, its been designed to ensure that you can manipulate an XML document slavishly following all the validity constraints of the schema (eg Social Security Nos have to match a regexp, not just "setSSN(String ssn) {this.ssn=ssn}"). If you're not trying to do round-trip edits on XML, or interop based on an agreed schema, JAXB is not for you.
Incidentally this is why JAXB has to use getters and setters, if you go the MS way you'll end up with data thats not been validated.
Betwixt, on the other hand, is a tool aimed at doing exactly what you are trying to do.
Personally, to produce data to match a schema "on the fly", I serialize using an in-house tool (for reasons that arent irrelevant here) to a "simple and obvious" XML format then transform the result with XSL to match the particular schema we need. Save us trying to handle fiddly details like 'elementFormDefault="qualified"' from the schema. We also transform on the way in. This method is dead easy but unlike JAXB it tends to be lossy - you just ser/deser the bits you want.
I use java's own XMLEncoder quite a bit, but it has one *big* gotcha that stops me using it more - default values of properties don't get serialized. If this was optional it'd be just dandy.