use of org.bson.json.JsonWriter in project mongo-java-driver by mongodb.
the class BasicDBObject method toJson.
/**
* Gets a JSON representation of this document
*
* @param writerSettings the json writer settings to use when encoding
* @param encoder the BasicDBObject codec instance to encode the document with
* @return a JSON representation of this document
* @throws org.bson.codecs.configuration.CodecConfigurationException if the registry does not contain a codec for the document values.
*/
public String toJson(final JsonWriterSettings writerSettings, final Encoder<BasicDBObject> encoder) {
JsonWriter writer = new JsonWriter(new StringWriter(), writerSettings);
encoder.encode(writer, this, EncoderContext.builder().build());
return writer.getWriter().toString();
}
use of org.bson.json.JsonWriter in project mongo-java-driver by mongodb.
the class MongoCommandException method getResponseAsJson.
private static String getResponseAsJson(final BsonDocument commandResponse) {
StringWriter writer = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(writer);
new BsonDocumentCodec().encode(jsonWriter, commandResponse, EncoderContext.builder().build());
return writer.toString();
}
use of org.bson.json.JsonWriter in project mongo-java-driver by mongodb.
the class LazyDBObject method toString.
/**
* Returns a JSON serialization of this object
*
* @return JSON serialization
*/
public String toString() {
JsonWriter writer = new JsonWriter(new StringWriter(), JsonWriterSettings.builder().build());
DBObjectCodec.getDefaultRegistry().get(LazyDBObject.class).encode(writer, this, EncoderContext.builder().isEncodingCollectibleDocument(true).build());
return writer.getWriter().toString();
}
use of org.bson.json.JsonWriter in project mongo-java-driver by mongodb.
the class Document method toJson.
/**
* Gets a JSON representation of this document
*
* @param writerSettings the json writer settings to use when encoding
* @param encoder the document codec instance to use to encode the document
* @return a JSON representation of this document
* @throws org.bson.codecs.configuration.CodecConfigurationException if the registry does not contain a codec for the document values.
*/
public String toJson(final JsonWriterSettings writerSettings, final Encoder<Document> encoder) {
JsonWriter writer = new JsonWriter(new StringWriter(), writerSettings);
encoder.encode(writer, this, EncoderContext.builder().build());
return writer.getWriter().toString();
}
use of org.bson.json.JsonWriter in project mongo-java-driver by mongodb.
the class Geometry method toJson.
/**
* Converts to GeoJSON representation
*
* @return the GeoJSON representation
*/
@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" })
public String toJson() {
StringWriter stringWriter = new StringWriter();
JsonWriter writer = new JsonWriter(stringWriter, JsonWriterSettings.builder().build());
Codec codec = getRegistry().get(getClass());
codec.encode(writer, this, EncoderContext.builder().build());
return stringWriter.toString();
}
Aggregations