如何将流 API json 与杰克逊一起使用?请参阅下面的代码:
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> map = new HashMap<String, Object>();
List<Object> list = new ArrayList<Object>();
// Get images in database
try {
Class.forName(DRIVER);
connection = DriverManager.getConnection(URL, USER, PASSWORD);
Statement s = connection.createStatement();
ResultSet r = s.executeQuery("select * from images");
while (r.next()) {
byte[] imageBytes = r.getBytes("image");
String imageBase64 = DatatypeConverter.printBase64Binary(imageBytes);
list.add(imageBase64);
}
} catch (SQLException e) {
}
map.put("images", list);
// Stream Json API
try {
mapper.writeValue(new File("c:\\images.json"), map);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
总是从内存中返回。我不知道将流与杰克逊一起使用。我使用超大 json,平均 2000 张图像,每个图像都有一个 imageBase64。我究竟做错了什么?