Search in sources :

Example 1 with Codec

use of org.bson.codecs.Codec in project mongo-java-driver by mongodb.

the class GeometryCodecHelper method encodeCoordinateReferenceSystem.

@SuppressWarnings({ "unchecked", "rawtypes" })
static void encodeCoordinateReferenceSystem(final BsonWriter writer, final Geometry geometry, final EncoderContext encoderContext, final CodecRegistry registry) {
    if (geometry.getCoordinateReferenceSystem() != null) {
        writer.writeName("crs");
        Codec codec = registry.get(geometry.getCoordinateReferenceSystem().getClass());
        encoderContext.encodeWithChildContext(codec, writer, geometry.getCoordinateReferenceSystem());
    }
}
Also used : Codec(org.bson.codecs.Codec)

Example 2 with Codec

use of org.bson.codecs.Codec in project mongo-java-driver by mongodb.

the class DBObjectCodec method writeValue.

@SuppressWarnings("unchecked")
private void writeValue(final BsonWriter bsonWriter, final EncoderContext encoderContext, @Nullable final Object value) {
    if (value == null) {
        bsonWriter.writeNull();
    } else if (value instanceof DBRef) {
        encodeDBRef(bsonWriter, (DBRef) value, encoderContext);
    } else if (value instanceof Map) {
        encodeMap(bsonWriter, (Map<String, Object>) value, encoderContext);
    } else if (value instanceof Iterable) {
        encodeIterable(bsonWriter, (Iterable) value, encoderContext);
    } else if (value instanceof BSONObject) {
        encodeBsonObject(bsonWriter, (BSONObject) value, encoderContext);
    } else if (value instanceof CodeWScope) {
        encodeCodeWScope(bsonWriter, (CodeWScope) value, encoderContext);
    } else if (value instanceof byte[]) {
        encodeByteArray(bsonWriter, (byte[]) value);
    } else if (value.getClass().isArray()) {
        encodeArray(bsonWriter, value, encoderContext);
    } else if (value instanceof Symbol) {
        bsonWriter.writeSymbol(((Symbol) value).getSymbol());
    } else {
        Codec codec = codecRegistry.get(value.getClass());
        encoderContext.encodeWithChildContext(codec, bsonWriter, value);
    }
}
Also used : OverridableUuidRepresentationCodec(org.bson.codecs.OverridableUuidRepresentationCodec) Codec(org.bson.codecs.Codec) CollectibleCodec(org.bson.codecs.CollectibleCodec) Symbol(org.bson.types.Symbol) BSONObject(org.bson.BSONObject) BSONObject(org.bson.BSONObject) HashMap(java.util.HashMap) BsonTypeClassMap(org.bson.codecs.BsonTypeClassMap) Map(java.util.Map) BsonTypeCodecMap(org.bson.codecs.BsonTypeCodecMap) CodeWScope(org.bson.types.CodeWScope)

Example 3 with Codec

use of org.bson.codecs.Codec in project mongo-java-driver by mongodb.

the class DBRefCodec method encode.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void encode(final BsonWriter writer, final DBRef value, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeString("$ref", value.getCollectionName());
    writer.writeName("$id");
    Codec codec = registry.get(value.getId().getClass());
    codec.encode(writer, value.getId(), encoderContext);
    if (value.getDatabaseName() != null) {
        writer.writeString("$db", value.getDatabaseName());
    }
    writer.writeEndDocument();
}
Also used : Codec(org.bson.codecs.Codec)

Example 4 with Codec

use of org.bson.codecs.Codec in project mongo-java-driver by mongodb.

the class GeometryEncoderHelper method encodeCoordinateReferenceSystem.

@SuppressWarnings({ "unchecked", "rawtypes" })
static void encodeCoordinateReferenceSystem(final BsonWriter writer, final Geometry geometry, final EncoderContext encoderContext, final CodecRegistry registry) {
    CoordinateReferenceSystem coordinateReferenceSystem = geometry.getCoordinateReferenceSystem();
    if (coordinateReferenceSystem != null) {
        writer.writeName("crs");
        Codec codec = registry.get(coordinateReferenceSystem.getClass());
        encoderContext.encodeWithChildContext(codec, writer, coordinateReferenceSystem);
    }
}
Also used : Codec(org.bson.codecs.Codec) CoordinateReferenceSystem(com.mongodb.client.model.geojson.CoordinateReferenceSystem)

Example 5 with Codec

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

the class GeoWithinFilter method encode.

@Override
public final void encode(Datastore datastore, BsonWriter writer, EncoderContext context) {
    writer.writeStartDocument(path(datastore.getMapper()));
    writer.writeStartDocument(getName());
    writer.writeName("$geometry");
    Object shape = getValue();
    if (shape != null) {
        Codec codec = datastore.getCodecRegistry().get(shape.getClass());
        codec.encode(writer, shape, context);
    }
    writer.writeEndDocument();
    writer.writeEndDocument();
}
Also used : Codec(org.bson.codecs.Codec)

Aggregations

Codec (org.bson.codecs.Codec)28 DocumentWriter (dev.morphia.mapping.codec.writer.DocumentWriter)5 Document (org.bson.Document)4 Stage (dev.morphia.aggregation.experimental.stages.Stage)3 Map (java.util.Map)3 BaseReferenceCodec (dev.morphia.mapping.codec.BaseReferenceCodec)2 ReferenceException (dev.morphia.mapping.lazy.proxy.ReferenceException)2 List (java.util.List)2 BsonDocument (org.bson.BsonDocument)2 BsonDocumentWriter (org.bson.BsonDocumentWriter)2 BsonTypeClassMap (org.bson.codecs.BsonTypeClassMap)2 CollectibleCodec (org.bson.codecs.CollectibleCodec)2 CoordinateReferenceSystem (com.mongodb.client.model.geojson.CoordinateReferenceSystem)1 ExpressionList (dev.morphia.aggregation.experimental.expressions.impls.ExpressionList)1 PropertyHandler (dev.morphia.mapping.codec.pojo.PropertyHandler)1 PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1