我有一个没有 rootElement 名称的 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>]
如何根据上述内容进行解组?谢谢
轻松版:1.1 RC2