I am using MongoDB Driver Java API to convert BSON to JSON.
I have test code like this.
String input = "{ \"timestamp\" : 1486064586641 }";
org.bson.Document doc = org.bson.Document.parse(input);
System.out.println("input = " + input);
System.out.println("output = " + doc.toJson());
The output is:
input = { "timestamp" : 1486064586641 }
output = { "timestamp" : { "$numberLong" : "1486064586641" } }
Is there an easy way to make the output look like the input?
解决方案
BSON Documnet's toJson method supports only output to MongoDB Extended JSON (STRICT or SHELL format). If you want to have regular JSON, you can use com.mongodb.util.JSON class:
String input = "{ \"timestamp\" : 1486064586641 }&

本文介绍了如何使用MongoDB驱动程序Java API将BSON文档转换为与输入类似的原始JSON格式,通过调整JsonWriterSettings的模式来避免MongoDB扩展JSON的输出。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



