Generating hashCode() and equals() when creating Java classes using Mojo Jaxb2 maven plugin

JAXB2 Basics you’re mentioning is not a property of maven-jaxb2-plugin, it is a standalone set of JAXB 2.x plugins you can use with XJC – or jaxb2-maven-plugin or whatever. <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxb2-maven-plugin</artifactId> <version>1.3.1</version> <executions> <execution> <id>xjc</id> <goals> <goal>xjc</goal> </goals> </execution> </executions> <configuration> <arguments> <argument>-Xequals</argument> <argument>-XhashCode</argument> </arguments> </configuration> <dependencies> <dependency> <groupId>org.jvnet.jaxb2_commons</groupId> <artifactId>jaxb2-basics</artifactId> <version>0.12.0</version> </dependency> </dependencies> </plugin> … Read more

Can JAXB marshal by containment at first then marshal by @XmlIDREF for subsequent references?

You can leverage the concept of JAXB’s XmlAdapter to do something like the following: input.xml The following is the XML document I will use for this example. The 3rd phone-number entry is a reference to the 1st phone-number entry, and the 5th phone-number entry is a reference to the 4th.: <?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?> <customer> … Read more

Is it possible to customize the namespace prefix that JAXB uses when marshalling to a String?

http://hwellmann.blogspot.com/2011/03/jaxb-marshalling-with-custom-namespace.html This shows how to do it. Another: http://www.systemmobile.com/?p=280 Key bits in case that link dies too: the NamespacePrefixMapper class, found in the com.sun.xml.bind.marshaller package. The abstract class has one method to implement: public abstract String getPreferredPrefix( String namespaceUri, String suggestion, boolean requirePrefix); then Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(”com.sun.xml.bind.namespacePrefixMapper”, new MyNamespacePrefixMapper()); If you’re also using … Read more

How do you customize how JAXB generates plural method names?

By default the following is generated for your schema fragment: import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = “physicianList”, propOrder = { “physician” }) public class PhysicianList { @XmlElement(name = “Physician”) protected List<Physician> physician; public List<Physician> getPhysician() { if (physician == null) { physician = new ArrayList<Physician>(); } … Read more

Which artifacts should I use for JAXB RI in my Maven project?

After clarification with Oracle, the following artifacts should be used: Runtime If you want to unmarshal XML to Java objects or marshal Java objects as XML: <dependency> <groupId>org.glassfish.jaxb</groupId> <artifactId>jaxb-runtime</artifactId> <version>…</version> </dependency> Schema compiler (XJC) If you have an XML Schema and want to generate the Java code out of it: <dependency> <groupId>org.glassfish.jaxb</groupId> <artifactId>jaxb-xjc</artifactId> <version>…</version> </dependency> … Read more

JAXB: how to marshall map into value

There may be a valid reason why you want to do this, but generating this kind of XML is generally best avoided. Why? Because it means that the XML elements of your map are dependent on the runtime contents of your map. And since XML is usually used as an external interface or interface layer … Read more