繁体   English   中英

Jaxb(json)解组错误,如何在没有根元素名称的情况下解组数据

[英]Jaxb (json) unmarshall error, how to unmarshall the data without the name of root element

我有一个不具有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>]

如何根据以上内容进行解组? 谢谢

resteasy版本:1.1 RC2

json设置不正确。

{"dataobjectname" : {name: "Anthony", source: "DS"}}

dataobjectname应该与方法中定义的变量名匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM