Created
March 5, 2016 13:11
-
-
Save benson-basis/ca3416dc715afc0e4d3a to your computer and use it in GitHub Desktop.
an example of writing to MongoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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