import java.io.UnsupportedEncodingException;
import java.util.List;
import org.json.JSONObject;
import org.bson.Document;
public class ReadJSONExample{
public static void main(
String[] args) throws UnsupportedEncodingException {
JSONObject obj = new JSONObject();
obj.put("name", "foo");
obj.put("num", 100);
obj.put("balance", 1000.21);
obj.put("is_vip", true);
obj.put("nickname","hi");
byte[] objAsBytes = obj.toString().getBytes();
Document
doc = convertByteIntoDocument(objAsBytes);
List<? extends Document> doc2 = (List<? extends Document>) doc;
ReadJSONExample.insertIntoDB(doc2);
}
private static void insertIntoDB(List<? extends Document> message) {
// inserting bson Document into DB
}
}