Skip to content

JAXB XML ElementWrapper Plugin

Laurent Schoelens edited this page Dec 6, 2023 · 1 revision

When generating XML schema from Java source code using the schemagen tool a common approach is to use the @XmlElementWrapper and @XmlElement annotations to handle schema generation for collections.

However, when generating Java source from a schema using the xjc tool the resulting code is not created with these annotations.

Instead, the generated Java source contains "injected" inner classes to accommodate the collection of elements contained within an element.

This plugins solve this by generating the corresponding @XmlElementWrapper annotation on corresponding fields to remove the need of nested inner classes.

Added in 4.0.1 version of JAXB-Tools.

Usage

  • Activate the plugin using the -XelementWrapper switch.

You can also use the following switches to change the plugin behaviour :

  • -XelementWrapper:delete : remove generated inner class from output - if not specified, inner class generated are kept
  • -XelementWrapper:include <file> : specify candidates classes in file to proceed
  • -XelementWrapper:exclude <file> : specify candidates classes in file to ignore
  • -XelementWrapper:summary <file> : output the summary of operation in specified file
  • -XelementWrapper:collection <classname> : specify the classname for collections - defaults to java.util.ArrayList
  • -XelementWrapper:instantiate <EAGER/LAZY> : specify if field is initialized EAGER (field = new ...) or LAZY (if (field == null) field = new ...) - defaults to EAGER

See Using JAXB2 Basics Plugins.

Clone this wiki locally