我有一个 Web 应用程序,我在其中从我的域对象生成 POJO。我的一个域对象包含一个映射,JAXB 生成以下模式:
<xs:element name="persons">
<xs:complexType>
<xs:sequence>
<xs:element name="entry" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="key" minOccurs="0" type="xs:string"/>
<xs:element name="value" minOccurs="0" type="person"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
这是从HashMap<String, Person>
人员产生的:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "personConfiguration", propOrder = {
"persons",
})
@XmlRootElement(name = "personConfiguration")
public class PersonConfiguration
{
@XmlElement(required = true)
protected PersonConfiguration.Persons persons;
/**
* Gets the value of the persons property.
*
* @return
* possible object is
* {@link PersonConfiguration.Persons }
*
*/
public PersonConfiguration.Persons getPersons() {
return persons;
}
/**
* Sets the value of the persons property.
*
* @param value
* allowed object is
* {@link PersonConfiguration.Persons }
*
*/
public void setPersons(PersonConfiguration.Persons value) {
this.persons = value;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"entry"
})
public static class Persons
{
protected List<PersonConfiguration.Persons.Entry> entry;
/**
* Gets the value of the entry property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the entry property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getEntry().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link PersonConfiguration.Persons.Entry }
*
*
*/
public List<PersonConfiguration.Persons.Entry> getEntry() {
if (entry == null) {
entry = new ArrayList<PersonConfiguration.Persons.Entry>();
}
return this.entry;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"key",
"value"
})
public static class Entry
{
protected String key;
protected Person value;
/**
* Gets the value of the key property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getKey() {
return key;
}
/**
* Sets the value of the key property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setKey(String value) {
this.key = value;
}
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link Person }
*
*/
public Person getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value
* allowed object is
* {@link Person }
*
*/
public void setValue(Person value) {
this.value = value;
}
}
}
}
正如所见,JAXB 添加了这一额外级别的间接条目 -> 键、值。难题的其他部分是 Spring MVC,使用 JSON 对象的 REST 调用。
现在基于 XML 的 REST 调用在上面的对象模式下工作得很好,但是当使用具有相同模式的 JSON 消息发送相同的调用时,我得到一个 JSONMappingException。
关于为什么会发生这种情况的任何想法?