27 October 2010

JAXB–Default Constructor

Working with JAXB, you need to have an empty constructor within your class. Any class that you are referring to from within your class is better to have this empty constructor class. I am using JAXB as part of Jetty Framework.
One other note: if you want to return result as a group (something that indent a little bit), then you need to return it as a separate class, which is a List (or ArrayList) of some other class (preferably String class).
If you want something to be shown this way:

you shouldn’t specify an XMLElement at the level of definition of the attribute in your class. If you do that, all the XML elements’ names will be the same. This way the first element will be different than the child nodes, which is really desirable.
Note: Apparently this only works in one level, you can not have multiple levels. I have tried creating different levels of classes, subclasses, inner classes, child classes but no one works. The best way to do is to use the following code
@XmlElementWrapper(name = "initialValues")
public List initialValueEntries;
and then Wrap things up in an XMLElementWrapper.
You can learn more about the default constructor of classes using the JAXB framework here.

No comments:

Post a Comment