Доброго времени суток. Использую библиотеку gson. Есть такой вот код:
RemoveModel removeModel = gson.fromJson(json, RemoveModel.class);
Есть json:
{
"item1": {
"remove": [
{
"id": "this_is_id",
"elements": [
"Element1",
"Element2"
]
}
]
},
"item2": {
"remove": [
{
"id": "this_is_id",
"elements": [
"Element1",
"Element2"
]
}
]
},
"item3": {
"remove": [
"this_is_id"
]
}
}
Однако вылазит ошибка:
Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
Что может быть не так?
Сами класс RemoveModel и другие:
Классы
//RemoveModel.java:
public class RemoveModel {
Item1Item2Model item1;
Item1Item2Model item2;
Item3Model item3;
public Item1Item2Model getItem1() {
return item1;
}
public void setItem1(Item1Item2Model item1) {
this.item1 = item1;
}
public Item1Item2Model getItem2() {
return item2;
}
public void setItem2(Item1Item2Model item2) {
this.item2 = item2;
}
public Item3Model getItem3() {
return item3;
}
public void setItem3(Item3Model item3) {
this.item3 = item3;
}
}
//Item1Item2Model.java:
public class Item1Item2Model {
private List<Item1Item2RemoveModel> remove;
public List<Item1Item2RemoveModel> getRemove() {
return remove;
}
public void setRemove(List<Item1Item2RemoveModel> remove) {
this.remove = remove;
}
}
//Item1Item2RemoveModel.java:
public class Item1Item2RemoveModel {
private String id;
private String[] elements;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String[] getElements() {
return elements;
}
public void setElements(String[] elements) {
this.elements = elements;
}
}
//Item3Model.java:
public class Item3Model {
String[] remove;
public String[] getRemove() {
return remove;
}
public void setRemove(String[] remove) {
this.remove = remove;
}
}