jaxb2-rich-contract-plugin
jaxb2-rich-contract-plugin copied to clipboard
fluent-builder and jaxb-xew-plugin do not work well together
Hi,
I'm trying to use fluent-builder and jaxb-xew-plugin together and it does not work. jaxb-xew-plugin I need to use to optimize the jaxb generation regarding collections using XmlElementWrapper annotations. I attached a small test project that shows that the two plugins do not work well together. jaxb-xew-plugin is executed first and then fluent-builder, but fluent-builder fails with an IndexOutOfBoundsException. Here is the output log file: log.txt and here is the test project: jaxbgeneration.zip
Best regards, Mihnea
yes having the same issue.
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution xsd-generate of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate failed: Index: 0 at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207) ... 20 more Caused by: java.lang.IndexOutOfBoundsException: Index: 0 at java.util.Collections$EmptyList.get(Collections.java:4454) at com.kscs.util.plugins.xjc.BuilderGenerator.generateBuilderMember(BuilderGenerator.java:135) at com.kscs.util.plugins.xjc.BuilderGenerator.buildProperties(BuilderGenerator.java:691) at com.kscs.util.plugins.xjc.FluentBuilderPlugin.run(FluentBuilderPlugin.java:121) at com.sun.tools.xjc.model.Model.generateCode(Model.java:292) at org.jvnet.mjiip.v_2_2.XJC22Mojo.generateCode(XJC22Mojo.java:66) at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:41) at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:28) at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:505) at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:328) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
It seems xew-plugin modifies the code model in some other way. I'll have a look into the issue. Up until now, fluent-builder hasn't been tested with xew-plugin...
After looking into what xew-plugin does, it seems as if it's gonna be hard to support it, since xew-plugin changes the whole way a collection property is represented. Most certainly, the solution won't be generic, but it will be a "lex xew-plugin" to work around that specific behavior.
It would be very good if those two plugins would work together because I could not find yet a way to generate from XSD a good set of JAXB objects with fluent builders and copy constructs, but have in the same time also solved the "collections" problem, especially when the JAXB objects have to be transformed also to JSON.
One approach to have collections in XML is with a wrapper element, like:
<root> <items> <item>1</item> <item>2</item> </items> </root>
that has an XML schema with a complex type for "items" having a sequence of "item".
But that leads to a JAXB with such API: root.getItems().getItem()
that returns List<item>
that is not so easy to work with in Java, but also it doesn't serialize nicely in JSON:
{ items: {item: [1,2]} }
.
As the jaxb2-rich-contract plugin has many features it would be actually very good if it could take over also the collection optimization from xew-plugin.
jaxb-xew-plugin certainly solves a very common problem, and I agree that it will be very useful if the two plugins work together. I will set up an example project and try to find a way to support it
Thanks. As a starting project see also the one that I attached in my first comment.
Please retry with latest version 4.2.0.0. Btw I think there now is a standard solution in XJC for the problem xew-plugin solves.