Difference of Maven JAXB plugins
2016-05-23 12:20
489 查看
http://stackoverflow.com/questions/2432859/difference-of-maven-jaxb-plugins
http://kalssworld.blogspot.com/2015/02/jaxb2-annotate-plugin.html
I was using maven-jaxb2-plugin plugin to generate objects from a standard xsd and created a web service that accept from
xml and json types of DeliveryInfoNotification object. In my cxf-servlet there was org.codehaus.jackson.jaxrs.JacksonJsonProvider that was used for binding JSON content to and from POJOs.
Web service was working fine with xml requests but for json requests it was giving the following error.
Unrecognized field "deliveryInfoNotification" (Class oma.xml.rest.netapi.messaging._1.DeliveryInfoNotification), not marked
as ignorable
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "deliveryInfoNotification" (Class oma.xml.rest.netapi.messaging._1.DeliveryInfoNotification), not marked as ignorable
at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@c85f54d; line: 2, column: 33] (through reference chain:
oma.xml.rest.netapi.messaging._1.DeliveryInfoNotification["deliveryInfoNotification"])
In order to get rid of that I had to annotate the DeliveryInfoNotification with @JsonIgnoreProperties
How do I get annotations in generated POJOs?
Answer was to use JAXB2 Annotate Plugin.
After several trial and errors it worked. With some configurations it was not giving any errors but was not generating the annotations
which was a little frustrating. There were 2 options to configure annotations, add them in xsd or an external bindings file. I used the second option since it was not a great idea to change the standard xsd.
I got the following and had to add a dependency to the plugin to get rid of it.
Caused by: org.jvnet.annox.annotation.AnnotationClassNotFoundException: Annotation class [org.codehaus.jackson.annotate.JsonIgnoreProperties]
could not be found.
... 32 more
Caused by: java.lang.ClassNotFoundException: org.codehaus.jackson.annotate.JsonIgnoreProperties
Anyway here is the final configuration that worked.
In pom.xml build->plugins->
In binding.xjb
http://kalssworld.blogspot.com/2015/02/jaxb2-annotate-plugin.html
JAXB2 Annotate Plugin
I was using maven-jaxb2-plugin plugin to generate objects from a standard xsd and created a web service that accept fromxml and json types of DeliveryInfoNotification object. In my cxf-servlet there was org.codehaus.jackson.jaxrs.JacksonJsonProvider that was used for binding JSON content to and from POJOs.
Web service was working fine with xml requests but for json requests it was giving the following error.
Unrecognized field "deliveryInfoNotification" (Class oma.xml.rest.netapi.messaging._1.DeliveryInfoNotification), not marked
as ignorable
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "deliveryInfoNotification" (Class oma.xml.rest.netapi.messaging._1.DeliveryInfoNotification), not marked as ignorable
at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@c85f54d; line: 2, column: 33] (through reference chain:
oma.xml.rest.netapi.messaging._1.DeliveryInfoNotification["deliveryInfoNotification"])
In order to get rid of that I had to annotate the DeliveryInfoNotification with @JsonIgnoreProperties
How do I get annotations in generated POJOs?
Answer was to use JAXB2 Annotate Plugin.
After several trial and errors it worked. With some configurations it was not giving any errors but was not generating the annotations
which was a little frustrating. There were 2 options to configure annotations, add them in xsd or an external bindings file. I used the second option since it was not a great idea to change the standard xsd.
I got the following and had to add a dependency to the plugin to get rid of it.
Caused by: org.jvnet.annox.annotation.AnnotationClassNotFoundException: Annotation class [org.codehaus.jackson.annotate.JsonIgnoreProperties]
could not be found.
... 32 more
Caused by: java.lang.ClassNotFoundException: org.codehaus.jackson.annotate.JsonIgnoreProperties
Anyway here is the final configuration that worked.
In pom.xml build->plugins->
<plugin> <groupid>org.jvnet.jaxb2.maven2</groupid> <artifactid>maven-jaxb2-plugin</artifactid> <version>0.8.2</version> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration> <schemadirectory>src/main/resources/xsd</schemadirectory> <bindingdirectory>src/main/resources/xsd</bindingdirectory> <generatedirectory>${project.build.directory}/generated-sources/xjc</generatedirectory> <bindingfiles>binding.xjb</bindingfiles> <extension>true</extension> <args> <arg>-XtoString</arg> <arg>-Xequals</arg> <arg>-XhashCode</arg> <arg>-Xannotate</arg> </args> <plugins> <plugin> <groupid>org.jvnet.jaxb2_commons</groupid> <artifactid>jaxb2-basics</artifactid> <version>0.6.4</version> </plugin> <plugin> <groupid>org.jvnet.jaxb2_commons</groupid> <artifactid>jaxb2-basics-annotate</artifactid> <version>0.6.4</version> </plugin> </plugins> </configuration> <dependencies> <dependency> <groupid>org.codehaus.jackson</groupid> <artifactid>jackson-jaxrs</artifactid> <version>1.9.13</version> </dependency> </dependencies> </plugin>
In binding.xjb
<!--?xml version="1.0" encoding="UTF-8"?--> <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:annox="http://annox.dev.java.net" xsi:schemalocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" jaxb:extensionbindingprefixes="xjc annox" version="2.1"> <jaxb:bindings schemalocation="OMA-SUP-XSD_rest_netapi_messaging-V1_0-20130709-C.xsd" node="/xs:schema"> <jaxb:bindings node="xs:complexType[@name='DeliveryInfoNotification']"> <annox:annotate target="class"> <annox:annotate annox:class="org.codehaus.jackson.annotate.JsonIgnoreProperties" ignoreunknown="true"> </annox:annotate> </annox:annotate></jaxb:bindings> </jaxb:bindings> </jaxb:bindings>
相关文章推荐
- 持续部署单页应用的7大技巧
- js中使用el表达式,表达式值中带有换行解决方法
- CSS3变换
- 异步加载的JS如何在chrome浏览器断点调试?
- js:推荐一下layer,生产力组件
- json和js字面量对象对比以及json序列号和反序列化的技术细节
- html5 video.js 使用及兼容所有浏览器
- jQuery正则验证15/18身份证
- CSS应用:复杂背景图案
- 2016-5-23 jsp
- jQuery事件绑定.on()简要概述及应用
- ReactiveCocoa之RAC常用宏(十)
- 基于jquery的轻量级bootstrap校验插件
- HTML盒子模型
- jQuery事件绑定on()、bind()与delegate() 方法详解
- ReactiveCocoa之RAC合并(九)
- 初识Bootstrap及制作一个简单的页面
- ReactiveCocoa之RAC过滤(八)
- 基于BootStrap的图片轮播效果展示实例代码
- ReactiveCocoa之RAC映射(七)