Creating BSON object from JSON string

前端 未结 9 1672
眼角桃花
眼角桃花 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 04:14

    I would suggest using the toJson() and parse(String) methods of the BasicDBObject, because the JSON utility class has been @Depricated.

    import com.mongodb.BasicDBObject;
    
    public static BasicDBObject makeBsonObject(String json) {
        return BasicDBObject.parse(json);
    }
    
    public static String makeJsonObject(BasicDBObject dbObj) {
        return dbObj.toJson();
    }
    

提交回复
热议问题