1

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.

3
  • please share us your POJO class here Commented Nov 8, 2019 at 9:21
  • added JAVA POJO objects. thanks Commented Nov 8, 2019 at 9:27
  • 1
    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. Commented Nov 8, 2019 at 9:33

1 Answer 1

1
@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

Sign up to request clarification or add additional context in comments.

1 Comment

Cannot deserialize instance of sk.atlantissoftware.tetragrammaton.core.servlet.controllers.TetragrammatonController$Root out of START_ARRAY token

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.