JAXB2 Maven Plugin that generates getter that never return null | Read-only mirror of https://github.com/DSI-VD/xjc-non-null-getter — Canton de Vaud. Issues & pull requests at the source.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jean-Eric Cuendet (vd.ch) 4edcd0fc5d
Merge pull request #1 from DSI-VD/dependabot/maven/junit-junit-4.13.1
Bump junit from 4.12 to 4.13.1
2023-12-21 15:50:12 +01:00
src Jakarta namespace migration. 2023-12-21 07:41:47 +01:00
.gitignore Gather last version from git vd.ch 2018-08-27 11:24:45 +02:00
.travis.yml Cleanup build config 2019-05-02 12:10:27 +02:00
LICENSE Apache Licence 2018-08-25 16:10:26 +02:00
pom.xml [maven-release-plugin] prepare for next development iteration 2023-12-21 09:31:45 +01:00
README.md Update documentation. 2023-12-21 07:52:21 +01:00

Build Status

xjc-non-null-getter

Maven JAXB2 Plugin that adds getters, creating the corresponding object, and adding it to the attribute if null.

It requires Java 17.

Usage in maven pom.xml

In pom.xml, add the plugin:

<plugin>
    <groupId>org.jvnet.jaxb</groupId>
    <artifactId>jaxb-maven-plugin</artifactId>
    <version>3.0.1</version>
    <configuration>
        <strict>false</strict> <!-- see https://github.com/highsource/maven-jaxb2-plugin/wiki/Catalogs-in-Strict-Mode -->
        <schemaDirectory>src/main/resources/xsd</schemaDirectory>
        <schemaIncludes>
            <include>main.xsd</include>
        </schemaIncludes>
        <catalog>src/main/resources/catalog.xml</catalog>
        <bindingDirectory>src/main/resources</bindingDirectory>
        <bindingIncludes>
            <include>bindings.xml</include>
        </bindingIncludes>
        <args>
            <arg>-extension</arg>
            <arg>-Xvalue-constructor</arg>
            <arg>-XNonNullGetter-api</arg>
        </args>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.jvnet.jaxb</groupId>
            <artifactId>jaxb-plugins</artifactId>
            <version>${jaxb-plugins.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.dsivd.jaxb-plugins</groupId>
            <artifactId>xjc-non-null-getter</artifactId>
            <version>${xjc-non-null-getter.version}</version>
        </dependency>
    </dependencies>
</plugin>

Usage in Java code

TheBean tb = new TheBean();
// empty list
List<ThePerson> people = tb.getPersons();
// creates a ThePerson instance and adds it to the people list
ThePerson person = tb.person();
// Get address Entity, creates it if null
person.address().setStreet("Over there 3");
person.address().setTown("Los Angeles");
person.address().setZipCode(12345);

Configuring Maven to push to Maven Central

Create a user Token in oss.sonatype.org Go to

User -> Profile -> User token -> Generate

Add this config in $HOME/.m2/settings.xml

    <servers>
      <server>
        <id>ossrh</id>
        <username>USER TOKEN</username>
        <password>PASSWORD TOKEN</password>
      </server>
    </servers>

Releasing to Maven central

mvn release:prepare mvn release:perform

Then to see errors:

https://oss.sonatype.org/

Login with your Sonatype JIRA account