0
我有沒有rootElement的名稱的JSON數據是如下的名字:JAXB(JSON)編碼和解讀錯誤,如何來解讀數據,而根元素
{
name: "Anthony",
source: "DS"
}
我有一個java類,這是作爲遵循解組:
@XmlRootElement
@XmlAccessorOrder(XmlAccessOrder.UNDEFINED)
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
public class ObjectTest {
private String name;
private String source;
/* with Getter & Setter for "name" & "source" */
}
解組代碼:
JAXBContext jc = JettisonMappedContext.newInstance(ObjectTest.class);
MappedNamespaceConvention c = new MappedNamespaceConvention();
JettisonMappedMarshaller u= new JettisonMappedMarshaller(jc, c);
String text = "{name: \"Anthony\", source: \"DS\"}";
u.unmarshal(new StringReader(text));
例外:
[javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"name"). Expected elements are <{}objectTest>]
如何根據上述內容進行解組?由於
RestEasy的版本:1.1 RC2