Wednesday, 16 May 2012

adding set methods in JAXB for collections

Normally the JAXB generated classes will not contain set methods for collections. (The idea here is to access collections only using get as the basis assumption is the change only happens to the contents of the collection).

if you use the maven maven-jaxb2-plugin, then you can use collection-setter-injector plugin along with jaxb2 plugin to create set methods. Below is a sample configuration,


<plugin>

<groupId>org.jvnet.jaxb2.maven2</groupId>

<artifactId>maven-jaxb2-plugin</artifactId>

<executions>

<execution>

<goals>

<goal>generate</goal>

</goals>

<phase>generate-sources</phase>

</execution>

</executions>

<configuration>

<!-- This helps generate setter methods-->

<args>

<arg>-npa</arg>

<arg>-Xcollection-setter-injector</arg>

</args>

<extension>true</extension>

<episode>true</episode>

<plugins>

<!-- plugin to generate setter for collection-->

<plugin>

<groupId>net.java.dev.vcc.thirdparty</groupId>

<artifactId>collection-setter-injector</artifactId>

<version>0.5.0-1</version>

</plugin>

</plugins>          

</configuration>

</plugin>

0 comments:

Post a Comment