Why does JAXB 2 RI's XJC simple mode change collection names?
Asked Answered
P

2

12

JAXB simple binding mode modifies collection names to their plural 'version', e.g. "additionalData" becomes "additionalDatas". Is there any solution to change this behavior? I need to have a Java field name and methods name equal to XSD field name. My bindings file:

<?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" />
    <xjc:simple/>
  </globalBindings>
</bindings>
Pirate answered 1/3, 2011 at 14:6 Comment(0)
C
8

The "simple binding mode" is an extended feature of the JAXB RI (Metro). Making the collection property names plural was part of its design.

From: http://weblogs.java.net/blog/kohsuke/archive/2007/01/using_jaxb_ris.html

My favorite feature in the JAXB RI is the simpler and better binding mode, which makes the generated code even easier to use, by ...

  1. Eliminating JAXBElement as much as possible
  2. Giving you a better, more typed binding in general
  3. Use plural property names where applicable

You may be able to use the normal schema customizations to control the property name. Refer to one of my previous answers (link below):

Columbarium answered 1/3, 2011 at 14:17 Comment(3)
Is there any way to turn off this feature and keep using "simple binding mode"? Because I need it to add @XmlRootElement to generated classes.Pirate
page weblogs.java.net/blog/kohsuke/archive/2007/01/… is deadMicronucleus
web.archive.org/web/20080920034324/http://weblogs.java.net/blog/…Golden
L
0

Here is an example plugin configuration that leverages the JAXB2 Simplify Plugin which among other things can disable pluralization.

 <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
      <execution>
        <id>xjc</id>
        <goals>
          <goal>xjc</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <xjbSources>
        <xjbSource>src/main/resources/jaxb_bindings.xjb</xjbSource>
      </xjbSources>
      <sources>
        <source>${basedir}/schema.xsd</source>
      </sources>
      <outputDirectory>${basedir}/target/generated-sources/</outputDirectory>
      <packageName>${groupId}.${artifactId}</packageName>
      <clearOutputDir>true</clearOutputDir>
      <arguments>
        <argument>-Xsimplify-usePluralForm=false</argument>
      </arguments>
    </configuration>
    <dependencies>
<dependency>
  <groupId>org.jvnet.jaxb</groupId>
  <artifactId>jaxb-plugins</artifactId>
  <version>4.0.0</version>
</dependency>
    </dependencies>
  </plugin>
Larrabee answered 28/11, 2023 at 22:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.