I have the following Json String:
[512768,[1493990100000,1628.4,1628.2,1628.4,1628,7.6513558]]
I have no idea how to transform it into a Java object using Jackson, I don't really know how to do it when there are no keys. Ofcourse I know that I need to create an objectMapper etc ...
objectMapper.readValue(candle, CandleChannel.class);
But what I mean, is I have no clue how I should annotate the class. I tried many things but I just keep getting an error telling me that I can't parse it:
com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of application.model.CandleChannel out of START_ARRAY token
at [Source: [512768,[1493990100000,1628.4,1628.2,1628.4,1628,7.6513558]]; line: 1, column: 1]
So I just wonder how I should annotate the class? Can somebody give me a hand? This is The code I have so far:
public class CandleChannel {
@JsonProperty
private Long channelId;
@JsonProperty
private List<Candle> candles;
public CandleChannel() {
}
public Long getChannelId() {
return channelId;
}
public void setChannelId(Long channelId) {
this.channelId = channelId;
}
public List<Candle> getCandles() {
return candles;
}
public void setCandles(List<Candle> candles) {
this.candles = candles;
}
}
And this the inner object:
@JsonFormat(shape= JsonFormat.Shape.ARRAY)
public class Candle {
@JsonProperty
private Integer mts;
@JsonProperty
private Float open;
@JsonProperty
private Float close;
@JsonProperty
private Integer high;
@JsonProperty
private Float low;
@JsonProperty
private Float volume;
public Candle() {
}
public Integer getMts() {
return mts;
}
public void setMts(Integer mts) {
this.mts = mts;
}
public Float getOpen() {
return open;
}
public void setOpen(Float open) {
this.open = open;
}
public Float getClose() {
return close;
}
public void setClose(Float close) {
this.close = close;
}
public Integer getHigh() {
return high;
}
public void setHigh(Integer high) {
this.high = high;
}
public Float getLow() {
return low;
}
public void setLow(Float low) {
this.low = low;
}
public Float getVolume() {
return volume;
}
public void setVolume(Float volume) {
this.volume = volume;
}
}
There must be a way, but Im not sure how to transfor that into a Java object.