UPDATE!修复了,错误的公开声明价格属性是导致此错误发生的原因。
我正在尝试杰克逊在.json文件和对象之间进行转换。但是,我一直收到此错误"UnrecognizedPropertyException: Unrecognized field "Prices" (class imp.JsonDTO), not marked as ignorable (one known property: "Ticker"]"
。
我试图转换一个看起来像这样的json文件:
{
"Ticker": "AAPL",
"Prices": [
{
"Date": "1986-01-02T00:00:00",
"Value": 22.25,
"Action": "Sell"
},
{
"Date": "1986-01-03T00:00:00",
"Value": 22.38,
"Action": "Buy"
},
{
"Date": "1986-01-06T00:00:00",
"Value": 22.38,
"Action": "Sell"
}
]
}
我正在这样转换:
ObjectMapper mapper = new ObjectMapper();
File file = new File("INTC.json");
JsonDTO dto = mapper.readValue(file, JsonDTO.class);
我正在使用的DTO:
public class JsonDTO {
public String Ticker;
List<PriceDTO> Prices = new ArrayList<PriceDTO>();
}
和..
public class PriceDTO {
public String Date;
public double Value;
public String Action;
}
为&#34;价格&#34;尝试了几种不同的方法。但似乎无法把它弄好。谢谢你的帮助:)