1

I have a JSON array of array, like below:

[ 
    [1,2,"str"],
    [1,2,"str"],
    [1,2,"str"],
]

I want to convert this JSON to an array of objects. Actually I want each inner array to represent an object with the following class. Therefore the result is an array of MyType (Note that my class MyType has a constructor corresponding to the mentioned inner array):

class MyType {
 int x;
 int y;
 String text;
 
 public MyType(int x, int y, String text){
   this.x=x;
   this.y=y;
   this.text=text;
 }
}
m.ghoreshi
  • 782
  • 5
  • 12
  • Try to use `@JsonFormat(shape = JsonFormat.Shape.ARRAY)` annotation for class with `@JsonCreator` and `@JsonProperty` for constructor. You can deserialise it to an array `mapper.readValue(jsonFile, MyType[].class)` or `mapper.readValue(jsonFile, new TypeReference>(){})` . See also [How to deserialize generic List with Jackson?](https://stackoverflow.com/questions/61150873/how-to-deserialize-generic-listt-with-jackson/61154659#61154659) – Michał Ziober Sep 10 '20 at 22:24

0 Answers0