Skip to content

Instantly share code, notes, and snippets.

@benson-basis
Created March 5, 2016 13:11
Show Gist options
  • Save benson-basis/ca3416dc715afc0e4d3a to your computer and use it in GitHub Desktop.
Save benson-basis/ca3416dc715afc0e4d3a to your computer and use it in GitHub Desktop.
an example of writing to MongoDB
DBObject recordDbObject = new BasicDBObject();
Ticket outTicket = pruneTicket(record.getOutTicket());
try {
//serialize data
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectMapper mapper = JsonUtils.getObjectMapper(new BsonFactory());
mapper = AnnotatedDataModelModule.setupObjectMapper(mapper);
mapper.writeValue(baos, outTicket);
LazyBSONObject bson = new LazyBSONObject(baos.toByteArray(), new LazyBSONCallback());
recordDbObject.put("outTicket", bson);
} catch (IOException e) {
recordDbObject.put("outTicket", "Unserializable Json");
}
callUpdate(record.getRequestId(),
new BasicDBObject("requestId", record.getRequestId()),
new BasicDBObject().append("$set", recordDbObject));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment