我有一个REST服务,其响应对象如下:
dd-mm-yy
getXMLProp()方法用于XML响应,其中标签名称与Map prop的键匹配.getJSONProp方法用于JSON响应。
当我尝试从邮递员客户端调用服务时,它工作正常,但是当我尝试使用jersey客户端调用服务时,响应没有数据。可以有人建议如何在响应中填充JAXBElement ?
此外,reponse.getJSONProp()引发以下错误:
@XmlRootElement(name="testresponse")
class Test{
private Map<String, String> prop = new TreeMap<>();
@JsonAnyGetter
@XmlTransient
public Map<String, String> getJSONProp() {
return prop;
}
@XmlAnyElement(lax = true)
@JsonIgnore
public List<JAXBElement<String>> getXMLProp() {
List<JAXBElement<String>> el = new ArrayList<>();
for (Map.Entry<String, String> entry : prop.entrySet()) {
el.add(new JAXBElement<>(new QName(entry.getKey()), String.class, entry.getValue()));
}
return el;
}
@JsonAnySetter
public void addProp(String key, String value) {
prop.put(key, value);
}
public void setProp(Map<String, String> prop) {
this.prop = prop;
}
}
Jersey版本:1.12。 杰克逊版本:1.9.2
Jersey客户端配置如下:
java.lang.ClassCastException: org.apache.xerces.dom.ElementNSImpl cannot be cast to javax.xml.bind.JAXBElement
泽西客户端中使用的MediaType是MediaType.APPLICATION_XML。 有人可以建议我在这里缺少什么吗? 预先感谢。