I am trying to deserialize this JSON using Jackson and I'm having trouble with the array part which as you can see has no field names. What would the java code need to look like to deserialize this?
{
"foo":[
[
"11.25",
"0.88"
],
[
"11.49",
"0.78976802"
]
],
"bar":[
[
"10.0",
"0.869"
],
[
"9.544503",
"0.00546545"
],
[
"9.5",
"0.14146579"
]
]
}
Thanks,
bc
The closest mapping (without any more context) would be to make foo and bar each an array of double arrays (2-dimensional arrays).
public class FooBarContainer {
private final double[][] foo;
private final double[][] bar;
@JsonCreator
public FooBarContainer(@JsonProperty("foo") double[][] foo, @JsonProperty("bar") double[][] bar) {
this.bar = bar;
this.foo = foo;
}
}
To use:
public static void main(String[] args) throws IOException {
ObjectMapper mapper = new ObjectMapper();
FooBarContainer fooBarContainer = mapper.readValue(CONTENT, FooBarContainer.class);
//note: bar is visible only if main is in same class
System.out.println(fooBarContainer.bar[2][1]); //0.14146579
}
Jackson has no trouble deserializing that data into this class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With