Category Archives: JAXB

Creating an xml Source object from a String

I needed to create an xml source object so I could force an unmarshaller to return a specific type of object. Advertisements

Posted in Java, JAXB | Leave a comment

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

Adding an attribute to a wrapper in JAXB

I have a list in an object. I need to output this list in XML. Normally this would be accomplished by the following: This produces the following output This is great, until I have the need to add an attribute … Continue reading

Posted in Java, JAXB, json | Tagged , , , | 2 Comments

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

Dynamically changing the address of a CXF WS Client

UPDATE: THANKS to attel in the comments below, THIS NOW WORKS. I was using the response context object, when I should have been using the request context. I have a case where the test system is going to be different … Continue reading

Posted in CXF, Java, JAXB, SOAP, Spring | Tagged , , , , , | 4 Comments