Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jaxb doesn't preserve case of namespace in package

I'm using the codehaus jaxb2-maven-plugin, v1.5 to compile XSDs into POJOs, but the generated package name coerces the package name to lower case (so, if I have my target namespace as http://example.com/sampleNamespace, then the generated package is com.example.samplenamespace).

I've googled around a bit and found mostly people having problems with underscores getting munged to dots, and the solution for that, but I can't seem to find something specific for preserving the case of the namespace.

NB: I don't want to have to repeat myself and override the generated package name, so the generatePackage option in the maven config isn't for me.

Before finding about the underscore munging, I had tried that, and also a regular space - both stick a dot in there.

Any ideas?

Schema:

<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:t="http://example.com/sampleNamespace" targetNamespace="http://example.com/sampleNamespace"
jaxb:version="2.0">

    <complexType name="MyFirstClass">
        <sequence>
            <element name="MyFirstElement" type="string" />
        </sequence>
    </complexType>
</schema>

Maven config:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <goals>
                <goal>xjc</goal>
            </goals>
        </execution>
    </executions>
</plugin>
like image 822
Phil Avatar asked Nov 11 '22 19:11

Phil


1 Answers

You will need to leverage a JAXB bindings file to specify a package name if you do not want to use the one that JAXB generates based on common Java coding conversions.

<bindings 
  xmlns="http://java.sun.com/xml/ns/jaxb" 
  version="2.1">
  <bindings schemaLocation="schema.xsd">
    <schemaBindings>
      <package name="com.example.sampleNamespace"/>
    </schemaBindings>
  </bindings>
</bindings>
like image 172
bdoughan Avatar answered Nov 15 '22 04:11

bdoughan