Reputation: 1
I have a JSON data that do not have a rootElement's name which is as follow:
{
name: "Anthony",
source: "DS"
}
I do have a java class which is as follow for the unmarshalling:
@XmlRootElement
@XmlAccessorOrder(XmlAccessOrder.UNDEFINED)
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
public class ObjectTest {
private String name;
private String source;
/* with Getter & Setter for "name" & "source" */
}
Unmarshalling code:
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));
Exception:
[javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"name"). Expected elements are <{}objectTest>]
How can I do the unmarshalling based on the content above? Thanks
resteasy version: 1.1 RC2
Upvotes: 0
Views: 3038
Reputation: 271
The json is not set properly.
{"dataobjectname" : {name: "Anthony", source: "DS"}}
dataobjectname
should match with the variable name defined in the method.
Upvotes: 1