How to make generated classes contain Javadoc from XML Schema documentation

I’ve never been able to get regular xsd:documentation to be placed in the java source except if and only if it was a Complex Type. Documentation for elements, simple types, etc are ignored. So, I end up using jxb:javadoc. To do so, include the definition of xmlns:jxb=”http://java.sun.com/xml/ns/jaxb” in your <xsd:schema> element. Add a child to … Read more

How to generate a Java class which implements Serializable interface from xsd using JAXB?

Serializable Use xjc:serializable in a custom bindings file to add the java.io.Serializable interface to your classes along with a serialVersionUID: <?xml version=”1.0″ encoding=”UTF-8″?> <bindings xmlns=”http://java.sun.com/xml/ns/jaxb” xmlns:xsi=”http://www.w3.org/2000/10/XMLSchema-instance” xmlns:xjc=”http://java.sun.com/xml/ns/jaxb/xjc” xsi:schemaLocation=” http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd” version=”2.1″> <globalBindings> <serializable uid=”1″ /> </globalBindings> </bindings> toString() Use a superclass (see xjc:superClass) from which all your bound classes will inherit. This class won’t be … Read more

JAXB: How to change XJC-generated classes names when attr type is specified in XSD?

JAXB provides two ways to accomplish this: 1. Inline Schema Anntotations You can use JAXB schema annotations to control the class names. <xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema” xmlns:jaxb=”http://java.sun.com/xml/ns/jaxb” jaxb:version=”2.1″> <xs:complexType name=”itemType”> <xs:annotation> <xs:appinfo> <jaxb:class name=”Item”/> </xs:appinfo> </xs:annotation> <xs:attribute name=”id” type=”xs:string” use=”required”/> </xs:complexType> </xs:schema> 2. External Binding File This customization can also be done via and external binding file: … Read more

Generating a JAXB class that implements an interface

Unfortunately, it looks like the interface-injection plugin mentioned in some of the other answers is no longer well-supported. In fact, I’m having trouble finding the JAR for download. Thankfully, the JAXB2 Basics Plugins provides a similar mechanism for adding an interface to the generated JAXB stubs (see the Inheritance plugin). The Inheritance plugin documentation has … Read more

No @XmlRootElement generated by JAXB

To tie together what others have already stated or hinted at, the rules by which JAXB XJC decides whether or not to put the @XmlRootElement annotation on a generated class are non trivial (see this article). @XmlRootElement exists because the JAXB runtime requires certain information in order to marshal/unmarshal a given object, specifically the XML … Read more