Hi,
JAXB doesn't generate setters for collection types. When I try to map a POJO to JAXB class , since the setter method is mising, the collection is not getting mapped at all. I even tried to use JAXBBeanFactory and is-accessible = "true". But none of them seem to work. Is there any workaround for this?
Thanks,
lavsara
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Use the attribute is-accessible to declare that the field can be accessed directly. Dozer is able to access private properties that do not have getter or setter methods.
Hi,
JAXB doesn't generate setters for collection types. When I try to map a POJO to JAXB class , since the setter method is mising, the collection is not getting mapped at all. I even tried to use JAXBBeanFactory and is-accessible = "true". But none of them seem to work. Is there any workaround for this?
Thanks,
lavsara
Try this
Mapping a field with no get() or set() methods
Use the attribute is-accessible to declare that the field can be accessed directly. Dozer is able to access private properties that do not have getter or setter methods.
<field>
<a>fieldAccessible</a>
<b is-accessible="true">fieldAccessible</b>
</field>
Ref : http://dozer.sourceforge.net/documentation/custommethods.html
Cheers,
Saravanan N.
but this way is so hard, i need to configure many object and many fileld in xml, is there any way to enable all public fields?
I have identified the solution for this. You should use the setter plugin from JAXB2
Ref this link.
http://confluence.highsource.org/display/J2B/JAXB2+Basics+Plugins
Here is the ant target
<target name="generate-sources">
<taskdef name="xjc" classname="org.jvnet.jaxb2_commons.xjc.XJC2Task">
<!- XJC2 Task classpath ->
<classpath>
<fileset dir="${basedir}/lib">
<include name="activation-*.jar"/>
<include name="jaxb-api-*.jar"/>
<include name="jaxb-impl-*.jar"/>
<include name="jsr173_api-*.jar"/>
<include name="stax-api-*.jar"/>
<include name="jaxb2-basics-jaxb-xjc-*.jar"/>
<include name="jaxb-xjc-*.jar"/>
<include name="jaxb2-basics-ant-*.jar"/>
</fileset>
</classpath>
</taskdef>
<mkdir dir="${basedir}/target/generated-sources/xjc"/>
<xjc destdir="${basedir}/target/generated-sources/xjc" extension="true">
<arg line="
-Xsetters
-Xsetters-mode=direct
/>
<binding dir="${basedir}/src/main/resources">
<include name="**/*.xjb"/>
</binding>
<schema dir="${basedir}/src/main/resources">
<include name="**/*.xsd"/>
</schema>
<!- Plugins ->
<classpath>
<fileset dir="${basedir}/lib">
<!- JAXB2 Basics library ->
<include name="jaxb2-basics-*.jar"/>
<!- JAXB2 Basics library dependencies ->
<include name="jaxb2-basics-runtime-*.jar"/>
<include name="jaxb2-basics-tools-*.jar"/>
<include name="commons-beanutils-*.jar"/>
<include name="commons-lang-*.jar"/>
<include name="commons-logging-*.jar"/>
</fileset>
</classpath>
</xjc>
</target>
I use org.jvnet.jaxb2_commons with maven :
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<forceRegenerate>true</forceRegenerate>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<schemaIncludes>
<include>boa_core.xsd</include>
</schemaIncludes>
<generatePackage>fr.adami.refe.rest.dto</generatePackage>
<generateDirectory>src/main/java</generateDirectory>
</configuration>
</execution>
</executions>
<configuration>
<extension>true</extension>
<args>
<arg>-Xsetters</arg>
<arg>-Xsetters-mode=direct</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</build>
Hey,
For JAXB Collections without setter method I got a solution that really works :
http://btarlton.blogspot.sg/2014/08/dozer-deep-nestinga-different-approach.html
No need to add settor method in generated classes , just follow the above link solution.