1
votes

I use JAVA jackson to mapping JSON to JAVA pojo objects, my JSON file is:

[
  [
    {
      "name": "tetragrammatonList_stocks_headerColumn_amountStoreOther",
      "id": "amountStoreOther"
    },
    {
      "name": "tetragrammatonList_stocks_headerColumn_article.articleSubGroup.name",
      "id": "article.articleSubGroup.name"
    },
    .....
    {
      "name": "tetragrammatonList_stocks_headerColumn_article.producer.name",
      "id": "article.producer.name"
    }
  ],
  [
    {
      "name": "tetragrammatonList_stocks_headerColumn_articleEANs",
      "id": "articleEANs"
    },
    {
      "name": "tetragrammatonList_stocks_headerColumn_article.plu",
      "id": "article.plu"
    },
    {
      "name": "tetragrammatonList_stocks_headerColumn_article.name",
      "id": "article.name"
    },
    .....
    {
      "name": "tetragrammatonList_stocks_headerColumn_article.producer.name",
      "id": "article.producer.name"
    }
  ]
]

and after readValue I have this error message:

Cannot deserialize instance of .... out of START_ARRAY token

my POJO classes:

public class A
    {
        private String name;
        private String id;
        +get/set methods
    }

    public class B
    {
        private String name;
        private String id;
        +get/set methods
    }

    public class Root
    {
        private List<A> a;
        private List<B> b;
        +get/set methods
    }

Root root = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).readValue(jsonString, Root.class);

please, what are correct java pojos for this JSON format ? thanks.

1
please share us your POJO class hereYuriy Tsarkov
added JAVA POJO objects. thanksmary
You have a list (array) consisting of two lists. And why are you using 2 POJO classes that are exactly the same, one is enough.Joakim Danielson

1 Answers

1
votes
@Getter
@Setter
public class Root
    {
        private List<A> a;
    }
@Getter
@Setter
private class A
    {
        private String name;
        private String id;
    }
ObjectMapper mapper = new ObjectMapper();
List <Root> rt = mapper.readValue(json, List.class);

Try this one