JAXB无法将值转换为BigDecimal



在Spring Boot应用程序中,我使用maven-jaxb2-plugin从WSDL文件生成类:

<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>AUTODETECT</schemaLanguage>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
<generatePackage>pl.pantuptus.app.integration</generatePackage>
</configuration>
</plugin>

WSDL文件包含sales字段,定义为:

<s:element minOccurs="1" maxOccurs="1"
name="sales" type="s:decimal" />

它由maven-jaxb2-plugin转换为生成类的BigDecimal属性:

@XmlElement(name = "sales", required = true)
protected BigDecimal sales;

我在一个配置组件中显式配置JAXB Marshaller:

@Configuration
public class IntegrationConfig {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("pl.pantuptus.app.integration");
return marshaller;
}
@Bean
public MyClient myClient(Jaxb2Marshaller marshaller) {
MyClient client = new MyClient();
client.setDefaultUri("http://localhost:8080/ws");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}

我的问题是,当我从客户端调用WS端点时:

getWebServiceTemplate().marshalSendAndReceive(url, request)

我收到一个null值为sales属性的对象。

我的猜测是JAXB无法正确解析此属性,因为它在响应中具有基于逗号的格式。

<sales>23 771,08</sales>

问题来了:我如何告诉Jaxb2Marshaller(或任何其他Marshaller实现(如何将这样的字符串转换为BigDecimal?

IntegrationConfig中将验证器添加到整理器后:

marshaller.setValidationEventHandler(new MyValidationEventHandler());

我发现SOAP文档(销售值中有逗号(没有根据WSDL:进行验证

i.s.w.l.MyValidationEventHandler:链接异常:java.lang.NumberFormatException

我认为唯一的解决方案是请求正确的WSDL文件或向服务提供商请求正确的WS响应。

最新更新