Jan 14
Still without a proper name, X2J Beta 1 has been released today.
I implore you all to download either the Jar or the Tar.gz files and try them out, and perhaps send some issues and bugs to the issue tracker.
Beta 1′s features:
- Name of POJO and XML element Names of your POJOs can be generally Anything. To make X2J realise which class it should instanciate for which XML element, you can annotate the class with
@Name("myName"). - Elements and Attributes Your XML elements must have inner elements and attributes. Otherwise, what’s the point? Annotate
gettermethods with@Attributeor@Elementto tell X2J how to treat those elements and attributes, but don’t forget to providesettersas well! - Java Arrays Have an array in your class? Have no fear. Annotate the array with
@FixedSequence(size)and even with@Nameto generate and read the array to and from XML documents as a sequence of XML elements of the array’s type. - Primitives Primitives are supported completely and magically, even though they’re not annotated by any X2J annotations.
- Converters Got a class from the Java framework or a third party software provider? Want to use it in your parsing or serializing? Just annotate it with
@Converter(converter.class). An example converting theCalendarclass is available asCalendarConverter.
I’m sure there are some stuff I forgot. As for what’s coming:
- Collections As of now, only Java arrays are supported, so Collection inherited classes can’t be used (yet!).
- Primary Keys Discussed it thoroughly here, and generally they provide for a way to reuse serialized items, thus making an XML document substantially smaller, and re-creating the parsed object tree to be exactly as it was before serialization.
- Factories Provide a means of using interfaces in the X2J classes, and use a
@Factoryannotation to determine which class type to annotate. Note that it will also allow for different classes to be instanciated according to the element’s attributes, so this would be a really cool feature.
If you have suggestions, questions, or just bashes, I’m all ears. Please download and try it!
Edit: Some dependencies are required, please check out the comments for more information.
Liked Chaotic Java? It's free! But maybe you can
January 14th, 2006 at 8:42 pm
First bug: .jar file was packaged with source files and not class files. Oops.
Hope to fix this before anyone notices, but if you Do notice, be aware that you should download the sources in the .tar.gz file and that you need the resolver.jar, xercesimpl.jar and xml-apis.jar .jar files from Xalan-J for this to compile.
I will get an Ant build script attached with the sources next time. Sorry!
January 14th, 2006 at 9:14 pm
It’s okay to download the .jar file now, it contains the class files. However, remember that you need to download the dependencies stated in my previous comment!
January 16th, 2006 at 3:13 am
So how does X2J stack up against other XML binding frameworks? What advantages does it bring to the table? Why another framework?
January 16th, 2006 at 7:36 am
Well, Geoffrey, I have written about it before, and I’m willing to reiterate.
X2J is doing both reliable serialization and transparent XML binding.
Reliable serialization means (for me):
* a serialization that when deserialized, the object tree looks the same as when it was serialized.
* a serialization where the resulting XML is readable by any application and does not even resemble proprietary serialization mechanisms.
Transparent XML binding means (again, for me):
* a binding where you use your Own objects, and not generated objects, for the binding.
* a binding where no external configuration is needed, specifically XML Schema Definions.
This gives you the following advantages over other frameworks, methinks:
* No need for long XSD files. I’ve heard some people claiming they aren’t well enough into XSD because they’ve written only three pages of XSD for their application. These files are unmaintainable, unreadable and certainly cause a lot of problem in any application.
* No need to fear for your serialized data. What you serialize today you can deserialize tomorrow with anything you’d want – X2J will even generate an XSD for you if you choose to do your deserialization without X2J (suppose on a different language-platform.)
* You can start using X2J from the start, middle or end. Either generate X2J classes from an XSD schema and scrap that horrible thing for heaven’s come, or start annotating your beans today: Your XML is still the same XML, and with simple annotations with similar names to what you’ve come to know in the Schema files, annotations are easy. And even more extensive than you’d expect.
Obviously, not all features discussed here are in the current beta (for example, XSD generation) but they’re going in there before the release.
If you want, I’m willing to have an open conversation about the subject.