【发布时间】:2017-12-30 20:08:21
【问题描述】:
我需要用 java POJO 类映射一个 JSON 数组对象。 我写的代码是这样的:
// execute the client with get method
InputStream inputStream = getMethod.getResponseBodyAsStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
ObjectMapper objectMapper = new ObjectMapper();
JsonFactory jsonFactory = new JsonFactory();
List<OwnerDetail> owners = new ArrayList<>();
JsonParser jsonParser = jsonFactory.createJsonParser(inputStream);
if (jsonParser.nextToken() != null && jsonParser.)
{ // end-of-input
owners = objectMapper.readValue(bufferedReader, TypeFactory.defaultInstance().constructCollectionType(List.class, OwnerDetail.class));
}
上面的块给了我以下错误:
com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
at [Source: java.io.BufferedReader@5e66c5fc; line: 1, column: 1]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3029)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2971)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2128)
任何帮助将不胜感激。谢谢。
【问题讨论】: