use of dev.morphia.mapping.lazy.proxy.ReferenceException in project morphia by mongodb.
the class MorphiaReferenceCodec method encode.
@Override
public void encode(BsonWriter writer, MorphiaReference value, EncoderContext encoderContext) {
Object ids = value.getId(mapper, getEntityModelForField());
if (ids == null || (ids instanceof Collection && ((Collection<?>) ids).isEmpty()) || (ids instanceof Map && ((Map<?, ?>) ids).isEmpty())) {
throw new ReferenceException(Sofia.noIdForReference());
}
Codec codec = getDatastore().getCodecRegistry().get(ids.getClass());
codec.encode(writer, ids, encoderContext);
}
use of dev.morphia.mapping.lazy.proxy.ReferenceException in project morphia by mongodb.
the class ReferenceCodec method encode.
@Override
public void encode(BsonWriter writer, Object instance, EncoderContext encoderContext) {
Object idValue = collectIdValues(instance);
if (idValue != null) {
final Codec codec = getDatastore().getCodecRegistry().get(idValue.getClass());
codec.encode(writer, idValue, encoderContext);
} else {
throw new ReferenceException(Sofia.noIdForReference());
}
}
use of dev.morphia.mapping.lazy.proxy.ReferenceException in project morphia by mongodb.
the class ReferenceCodec method encode.
@Override
public Object encode(Object value) {
try {
DocumentWriter writer = new DocumentWriter(mapper);
document(writer, () -> {
writer.writeName("ref");
encode(writer, value, EncoderContext.builder().build());
});
return writer.getDocument().get("ref");
} catch (ReferenceException e) {
return value;
}
}
Aggregations