Search in sources :

Example 1 with Encoder

use of org.bson.codecs.Encoder in project morphia by mongodb.

the class IndexHelper method toBsonDocument.

@SuppressWarnings("unchecked")
private BsonDocument toBsonDocument(final String key, final Object value) {
    BsonDocumentWriter writer = new BsonDocumentWriter(new BsonDocument());
    writer.writeStartDocument();
    writer.writeName(key);
    ((Encoder) database.getCodecRegistry().get(value.getClass())).encode(writer, value, ENCODER_CONTEXT);
    writer.writeEndDocument();
    return writer.getDocument();
}
Also used : BsonDocumentWriter(org.bson.BsonDocumentWriter) BsonDocument(org.bson.BsonDocument) Encoder(org.bson.codecs.Encoder)

Aggregations

BsonDocument (org.bson.BsonDocument)1 BsonDocumentWriter (org.bson.BsonDocumentWriter)1 Encoder (org.bson.codecs.Encoder)1