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());
}
}
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);
}
}
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();
}
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);
}
}
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();
}
Aggregations