The idea is that I'd like to convert a JSON array ["foo", "bar"]
into a Java object so I need to map each array element to property by index.
Suppose I have the following JSON:
{
"persons": [
[
"John",
"Doe"
],
[
"Jane",
"Doe"
]
]
}
As you can see each person is just an array where the first name is an element with index 0 and the last name is an element with index 1.
I would like to deserialize it to List<Person>
.
I use mapper as follows:
mapper.getTypeFactory().constructCollectionType(List.class, Person.class)
where Person.class
is:
public class Person {
public final String firstName;
public final String lastName;
@JsonCreator
public Person(@JsonProperty() String firstName, @JsonProperty String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
}
I was wondering if I can somehow specify array index as @JsonProperty
argument instead of it's key name?