Category Archives: xml

Unmarshalling ambiguous objects

In a previous post, I showed how to use @XmlSeeAlso to inform the JAXB context of inheriting classes. This is great during marshalling. The real pain was on unmarshalling. A requirement we had was that there were two objects that … Continue reading

Posted in Java, JAXB, xml | Leave a comment

Specify the name of the xml element used by a property when marshalled by JAXB

JAXB by default would output the value of a getter for property “oldName” as <oldName>data</oldName>. Specify @XmlElement if you want to use a different name. Thanks to @XmlElement, it will be outputted as <newName>data</newName>. This is especially useful when you … Continue reading

Posted in Java, JAXB, xml | Leave a comment

Generating formatted xml when marshalling

After you create the marshaller but before you marshall, tell the marshaller to output formatted xml by:

Posted in Java, JAXB, xml | Leave a comment

Marshalling sub-classes

If you have class Animal and it is extended by Cat and Dog. How would you marshall them without having to duplicate code? You specify the parent class when you get the JAXB context instance. This will get you an … Continue reading

Posted in Java, JAXB, xml | Leave a comment

When a vanilla CXF Soap client isn’t enough

Normally, I have been able to generate a Soap client and be on my way. This particular time I had to perform some business logic on the client. One of the first things that I encountered was the nuisance of … Continue reading

Posted in Java, Maven, xml | Tagged , , | Leave a comment

Marshalling an object without @XmlRootElement

You would normally marshall an object to it’s XML String form by something similar to: This assumes that the object is annotated with @XmlRootElement. If it is not, then you have to create a root element for it, by something … Continue reading

Posted in Java, xml | Tagged , , , | Leave a comment

XML API Hell

Maven works great and solves lots of conflicting API problems for you.  The one case when it can’t help and usually hurts is when APIs change groupId or artifactId.  I recently had a case where I needed a CXF generated … Continue reading

Posted in Java, xml | 1 Comment