Creating BSON object from JSON string

前端 未结 9 1681
眼角桃花
眼角桃花 2020-12-01 03:10

I have Java app that takes data from external app. Incoming JSONs are in Strings. I would like to parse that Strings and create BSON objects.

Unfortunate I can\'t fi

9条回答
  •  被撕碎了的回忆
    2020-12-01 03:53

    ... And, since 3.0.0, you can:

    import org.bson.Document;
    
    final Document doc = new Document("myKey", "myValue");
    final String jsonString = doc.toJson();
    final Document doc = Document.parse(jsonString);
    

    Official docs:

    • Document.parse(String)
    • Document.toJson()

提交回复
热议问题