我的 WS 接口(interface):
@WebService
public interface WS{
String decide(String word, MapWrapper parameters);
}
使用包装类:
public class MapWrapper {
public HashMap<String, String> map;
}
和
from("cxf:http://localhost:8080/WS?serviceClass=ws.WS&dataFormat=POJO").to("stream:out"); //Just for testing purpose
使用 SOAPUI 调用时出现以下异常:
Error during type conversion from type: org.apache.cxf.message.MessageContentsList to the required type: byte[] with value [Test, ws.WS@1221bc6] due argument type mismatch
我认为 MapWrapper 类导致了这个异常。但如何解决这个问题呢?
最佳答案
同样的问题一遍又一遍......
请勿在作为 Web 服务公开的接口(interface)中使用 Java
特定的构造。我正在讨论HashMap
。
Web 服务是一种集成技术,旨在连接任何平台(甚至非 OO 客户端)中的组件。 Web服务中传递的所有对象都应该是值(value)传递对象。不是复杂的业务对象等。
这不仅是正确的方法,而且是编码和部署过程中问题最少的方法。
关于java - HashMap 与 Camel cxf :component POJO dataFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14914711/