JAXB, XJC -> create multiple class files

By default JAXB (JSR-222) will create static inner classes for nested complex types to prevent class name conflicts. You can use an external binding file to disable this behaviour. binding.xml A binding file allows you to customize how Java classes are generated from an XML schema. <jaxb:bindings xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:jaxb=”http://java.sun.com/xml/ns/jaxb” version=”2.1″> <jaxb:globalBindings localScoping=”toplevel”/> </jaxb:bindings> XJC Call … Read more

How to deal with JAXB ComplexType with MixedContent data?

As you mentioned you need to add the mixed attribute to indicate that your type supports mixed content. Without this specified your XML content is invalid: <xsd:complexType name=”TaxDescriptionType” mixed=”true”> <xsd:sequence> <xsd:element name=”ShortName” type=”xsd:string” /> </xsd:sequence> <xsd:attribute ref=”xml:lang” /> </xsd:complexType> The generated TaxDescriptionType class will have the following property. Essentially this means that all of the … Read more

How generate XMLElementWrapper annotation with xjc and customized binding

Bjarne Hansen developed a plugin for xjc that was able to take care of this. Unfortunately, the link to the original implementation is now dead. However, there is a project by Dmitry Katsubo on github, based on Bjarne’s original code with some additional improvements. → https://github.com/dmak/jaxb-xew-plugin (Just for reference: the original link, now dead: http://www.conspicio.dk/blog/bjarne/jaxb-xmlelementwrapper-plugin)

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