is Jackson Object Mapper
‘s ACCEPT_SINGLE_VALUE_AS_ARRAY
feature supposed to work with JsonFormat.Shape.ARRAY
??
I have:
@Test
@SneakyThrows
public void testCandlesSingleValueWsRes() {
String singleCandleValue = """
[158587,[1716181800000,67222,67224,67224,67222,0.0022]]
""";
mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.enable(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
BitfinexOhlcWsResp bitfinexOhlcWsResp = mapper.readValue(singleCandleValue, BitfinexOhlcWsResp.class);
Assert.assertNotNull(bitfinexOhlcWsResp);
}
with model:
@Data
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
public class BitfinexOhlcWsResp {
Integer channelId;
@JsonFormat(with = {JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY})
List<BitfinexCandle> candles;
}
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
public class BitfinexCandle {
long tstpMs; //Millisecond epoch timestamp
float open; //First execution during the time frame
float close; //Last execution during the time frame
float high; //Highest execution during the time frame
float low; //Lowest execution during the timeframe
float volume; //Quantity of symbol traded within the timeframe
}
and I get:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize a POJO (of type `com.broker.connector.bitfinex.entity.BitfinexCandle`) from non-Array representation (token: VALUE_NUMBER_INT): type/property designed to be serialized as JSON Array
at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 10] (through reference chain: com.broker.connector.bitfinex.model.quote.BitfinexOhlcWsResp["candles"]->java.util.ArrayList[0])
when I wrap data in another []
it works…
what am I missing?
‘jackson-core’: v.2.16.1