【发布时间】:2021-01-12 03:25:23
【问题描述】:
获取 MismatchedInputException。在这里搜索了很多问题,但还没有找到解决方案。
代码:
import /path/to/file/Bars;
List<Bars> barResults = null;
public boolean validateData() throws IOException {
boolean flag = false;
try {
if (Data.read() != -1) {
BufferedReader reader = new BufferedReader(new InputStreamReader(Data));
String line;
while ((line = reader.readLine()) != null) {
line = "[{" + line;
System.out.println(line);
ObjectMapper om = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Bars ms = om.readValue(line, Bars.class);
System.out.println(ms);
break;
}
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
return flag;
}
Json: //例如缩短
[{"createdOn":1601058721310,"lastUpdated":null,"lastUpdatedBy":null,"createdBy":null,"appId":null,"logical":"N","calculationDateTime":1601058721310,"mtaVersionNumber":null,"storageRegionName":"texas","createdOnDate":1601058721310,"lastUpdatedDate":0}]
输出:
[{"createdOn":1601058721310,"lastUpdated":null,"lastUpdatedBy":null,"createdBy":null,"appId":null,"logical":"N","calculationDateTime":1601058721310,"mtaVersionNumber":null,"storageRegionName":"texas","createdOnDate":1601058721310,"lastUpdatedDate":0}]
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `object` out of START_ARRAY token
at [Source: (StringReader); line: 1, column: 1]
我不确定是什么导致了这个异常。当我启动应用程序时,我运行并读取 JSON 很好..但抛出异常。
【问题讨论】:
标签: java json spring-boot spring-data-jpa jackson-databind