我需要使用最新版本jaxb:2.2.4-1,但maven或maven-jaxb2-plugin似乎从JDK中获取了一个.
我尝试指定这样的版本:
<configuration>
<specVersion>2.2</specVersion>
...
</configuration>
Run Code Online (Sandbox Code Playgroud)
但是日志显示:
[INFO] [jaxb2:generate {execution: common}]
[INFO] Started execution.
[INFO] JAXB API is loaded from the [jar:file:/opt/jdk1.6.0_24/jre/lib/rt.jar!].
[INFO] Detected JAXB API version [2.1].
Run Code Online (Sandbox Code Playgroud)
我试图将依赖项添加到正确版本的javax.xml.bind:jaxb-api和com.sun.xml.bind:jaxb-impl,但这没有帮助.
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.0</version>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.4-1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>common</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<specVersion>2.2</specVersion>
...
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用maven-jaxb22-plugin但它也没用.
我正在连接到外部 XML API,我正在尝试使用 JacksonXmlMapper类将其解析为 POJO 。XML 的一部分如下所示:
<invoice>
<some>element</some>
<some_other>element</some_other>
<currency>USD</currency>
<cost>10.42</cost>
<breakdown>
<item id="1">
<description>blah blah</description>
<cost>4.21</cost>
</item>
</breakdown>
</invoice>
Run Code Online (Sandbox Code Playgroud)
我想解析单个对象中的currency和cost元素Money。
更糟糕的是,内部items 仅指定成本并“重用”货币代码。我可以使用 Jackson 以某种智能方式解析它们吗?