This repository was archived by the owner on Nov 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
This repository was archived by the owner on Nov 18, 2021. It is now read-only.
BEGIN_OBJECT expected, but met NAME #33
Copy link
Copy link
Open
Description
Hi.
I'm having an issue while parsing an XML api response.
It's similar to this issue, but I can't change the XML like he did.
What am I doing wrong ?
My Error:
Process: myproject.com, PID: 26672
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: BEGIN_OBJECT expected, but met NAME
Scopes: INSIDE_OBJECT>NAME>INSIDE_OBJECT>INSIDE_EMBEDDED_ARRAY>INSIDE_OBJECT>NAME
Closed tags: 'person'/2
Token: null
Tokens queue: null
Values queue: person, null
My XML:
<website>
<person>
<id_person>60</id_person>
<name>Peter</name>
<personal_items>
<item>
<id>165</id>
<name>Phone</name>
</item>
<item>
...
</item>
</personal_items>
</person>
<person>
...
</person>
</website>
My Model:
public class Persons {
private List<Person> person;
//getters
}
public class Person {
String id_preson;
String name;
PersonalItems personal_items;
//getters
}
public class PersonalItems{
List<Item> item;
//getters
}
public class Item{
String id;
String name;
//getters
}
My Java code:
XmlParserCreator parserCreator = new XmlParserCreator() {
@Override
public XmlPullParser createParser() {
try {
return XmlPullParserFactory.newInstance().newPullParser();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
GsonXml gsonXml = new GsonXmlBuilder()
.setXmlParserCreator(parserCreator)
.setSameNameLists(true)
.create();
Persons persons = gsonXml.fromXml(xml, Persons.class);
Metadata
Metadata
Assignees
Labels
No labels