【发布时间】:2020-12-18 06:43:13
【问题描述】:
@XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class ItemSubstitutionRequestDTO { public ItemSubstitutionRequestDTO() { } private List<Map<String,Integer>> substituteFor=new ArrayList<Map<String,Integer>>(); private String orderId; public List<Map<String,Integer>> getSubstituteFor() { return substituteFor; } public void setSubstituteFor(List<Map<String,Integer>> substituteFor) { this.substituteFor = substituteFor; } public String getOrderId() { return orderId; } public void setOrderId(String orderId) { this.orderId = orderId; } }
最终结果错误:
java.util.Map是一个接口,JAXB不能处理接口。
我无法让 JaxB 编组/解组 Map 的实例。我也尝试了其他注释,发现这是解决上述错误的可能方法之一,但没有任何反应。
下面是来自UI端的输入json
{ "itemSubstitutionRequestDTO": { "substituteFor": [{"41712":2}], "orderId": "1073901", } }
【问题讨论】:
-
您的示例是 JSON,而不是 XML。 JAXB 仅适用于 XML。对于 JSON,您需要另一个框架,可能是 Jackson。
标签: java xml jaxb marshalling unmarshalling