How to use the stream API json with jackson? See my code below:
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();
}
Always return out of memory. I dont know to use stream with jackson. I working with extra large json, average 2000 images, to each image a imageBase64. what am I doing wrong?