我试图强制只包含一个元素的列表中的括号。JAXB JSON强制括号在阵列上
我想要这样的:
{“id”:“0”,“industries”:[{“id”:“0”,“name”:“Technologies”}],“name”:“ Google Inc.“}
但我得到:
{”id“:”0“,”industries“:{”id“:”0“,”name“:”Technologies“},”name“: “谷歌公司”}
这里是我的实体:
@Entity
@XmlRootElement
public class Company {
private int id;
private String name;
private String description;
@XMLElement(name="industries")
private List<Industry> industryList;
[...]
最后,我JAXB上下文解析器:
public JAXBContextResolver() throws Exception {
MappedBuilder builder = JSONConfiguration.mapped(); builder.arrays(“industries”); builder.rootUnwrapping(true);
this.context = new JSONJAXBContext(builder.build(),Company.class); }