Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 219
User123456789 Avatar asked Mar 01 '11 14:03

User123456789


People also ask

Is XJC a JAXB?

7.1. The JAXB-2 Maven plugin uses the JDK-supplied tool XJC, a JAXB Binding compiler tool that generates Java classes from XSD (XML Schema Definition). By default, this plugin locates XSD files in src/main/xsd.

What is JAXB RI?

JavaTM Architecture for XML Binding (JAXB) provides an API and tools that automate the mapping between XML documents and Java objects. JAXB makes XML easy to use by compiling an XML schema into one or more Java technology classes.

What is XJC?

XJC is a Java SE tool that compiles an XML schema file into fully annotated Java classes. It is distributed within the JDK package and is located at /bin/xjc path.

What is JAXB XJC jar?

Old JAXB XJC Contains source code needed for binding customization files into java sources. In other words: the *tool* to generate java classes for the given xml representation.


1 Answers

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):

  • How do you customize how JAXB generates plural method names?
like image 86
bdoughan Avatar answered Oct 14 '22 07:10

bdoughan