0

I have the following JSON:

{
  "name1" : "Jon Smith",
  "age1" : 25,
  "name2" : "Mary Carter",
  "age2" : 31
}

I would like to deserialize it to the following Java structure:

public class PersonList {
  private Person person1;
  private Person person2;
}

public class Person {
  private String name;
  private int age;
}

Is it possible with Jackson?

WonderCsabo
  • 11,471
  • 12
  • 57
  • 103

1 Answers1

-1

I am not sure, but you can try to convert the json into an array, loop through the array like this:

for(int i=0;i<array.length-1;i+=2){
    persons[i] = new Person(array[i],array[i+1]);
}

I know dinamic variables are not used in Java so I assumed you can use a vector (persons[])

Also , use this (How to parse a JSON and turn its values into an Array?) for converting JSON to array

Community
  • 1
  • 1
Marius Stanciu
  • 165
  • 1
  • 11