Issue
I want to create a Java class out of a json response I get from a third party API which I have already managed to to with using the ObjectMapper. However, in this specific case, the JSON response has no keys so I dont know how I can map this into an Object, basically how should I use @JsonProperty annotation if the json response looks like this
[
[
1499040000000, // Kline open time
"0.01634790", // Open price
"0.80000000", // High price
"0.01575800", // Low price
"0.01577100", // Close price
"148976.11427815", // Volume
1499644799999, // Kline Close time
"2434.19055334", // Quote asset volume
308, // Number of trades
"1756.87402397", // Taker buy base asset volume
"28.46694368", // Taker buy quote asset volume
"0" // Unused field, ignore.
]
]
Solution
You want to use:
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
@JsonPropertyOrder({ "foo", "bar" })
public class FooBar {
public String foo;
public String bar;
}
Example here:
- https://stackoverflow.com/a/38111311/5521670
- https://levelup.gitconnected.com/parsing-json-arrays-as-objects-with-jackson-c2620e7cc439
Answered By - Šimon Kocúrek
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.