Usage

Using the plugin is very easy. It has just to be called within the Maven project.

mvn com.cedarsoft.serialization.generator:serializer-generator-maven-plugin:generate \
  -Ddialect=JACKSON -Ddomain.class.pattern=src/main/java/com/cedarsoft/MyDomainObject.java

Shortening the command line

Either add an entry to your

It might be a good idea to add that entry to your $user.home/.m2/settings.xml

<pluginGroups>
  <pluginGroup>com.cedarsoft.serialization.generator</pluginGroup>
</pluginGroups>

Then it is possible to just call the plugin using

mvn serializer-generator:generate -Ddialect=STAX_MATE -Ddomain.class.pattern=src/main/java/com/cedarsoft/MyDomainObject.java

Generation process

This plugin analyzes the source code of the domain object source file. It then creates a serializer and corresponding unit tests using some simple heuristics.

Generating Serializers

This serializers are placed in target/generated-sources/cedarsoft-serialization-main

The serializers are compilable and can be used immediately.

Generating the Unit Tests

There are two unit tests generated for each serializer. They are placed in target/generated-sources/cedarsoft-serialization-test

Test Resources

Placeholder resources are generated in target/generated-sources/cedarsoft-serialization-test-resources

There just contain an XML fragment and should be filled when running the tests.

Generated Unit Tests

Two tests are generated for each serializer:

  • $SerializerClassTest: This is a round trip test for the current version
  • $SerializerClassVersionTest: This test is used to ensure that the current serializer is able to deserialize all (old) XML formats. This test will become important as soon as the format changes.

    To avoid unnecessary manual work and encourage the creation of this test, those stubs are created immediately.

Defining the plugin version

It is recommended to define the plugin version for each plugin. Therefore that section should be added to the pom.xml:

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>com.cedarsoft.serialization.generator</groupId>
        <artifactId>serializer-generator-maven-plugin</artifactId>
        <version>4.1.5</version>
      </plugin>
    </plugins>
  </pluginManagement>
</build>