【发布时间】:2019-12-17 03:05:15
【问题描述】:
我想将 json 数组转换为 POJO,它在 JVM 上运行但在 Android 上失败
这是我的pojo:
package com.binance.api.client.domain.market;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
@JsonPropertyOrder()
@JsonIgnoreProperties(ignoreUnknown = true)
public class Lilin {
public Long openTime;
public String open;
public String high;
public String low;
public String close;
public String volume;
public Long closeTime;
public String quoteAssetVolume;
public Long numberOfTrades;
public String takerBuyBaseAssetVolume;
public String takerBuyQuoteAssetVolume;
}
然后手动测试一下:
public void testCandlestickDeserializer() {
final String candlestickJson = "[\n" +
" 1499040000000,\n" +
" \"0.01634790\",\n" +
" \"0.80000000\",\n" +
" \"0.01575800\",\n" +
" \"0.01577100\",\n" +
" \"148976.11427815\",\n" +
" 1499644799999,\n" +
" \"2434.19055334\",\n" +
" 308,\n" +
" \"1756.87402397\",\n" +
" \"28.46694368\",\n" +
" \"17928899.62484339\"\n" +
" ]";
ObjectMapper mapper = new ObjectMapper();
try {
Lilin candlestick = mapper.readValue(candlestickJson, Lilin.class);
System.out.println(candlestick);
} catch (IOException e) {
System.err.println(e);
}
}
在 JVM 上尝试没有错误,但在 Android 上运行时出现此错误:
Cannot deserialize value of type `java.lang.Long` from String "0.01634790": not a valid Long value
@JsonPropertyOrder() 注释似乎在 Android 上无法正常工作
【问题讨论】: