use of org.bson.codecs.RepresentationConfigurable in project mongo-java-driver by mongodb.
the class LazyPropertyModelCodec method getCodecFromPropertyRegistry.
@SuppressWarnings("unchecked")
private Codec<T> getCodecFromPropertyRegistry(final PropertyModel<T> propertyModel) {
Codec<T> localCodec;
try {
localCodec = propertyCodecRegistry.get(propertyModel.getTypeData());
} catch (CodecConfigurationException e) {
return new LazyMissingCodec<>(propertyModel.getTypeData().getType(), e);
}
if (localCodec == null) {
localCodec = new LazyMissingCodec<>(propertyModel.getTypeData().getType(), new CodecConfigurationException("Unexpected missing codec for: " + propertyModel.getName()));
}
BsonType representation = propertyModel.getBsonRepresentation();
if (representation != null) {
if (localCodec instanceof RepresentationConfigurable) {
return ((RepresentationConfigurable<T>) localCodec).withRepresentation(representation);
}
throw new CodecConfigurationException("Codec must implement RepresentationConfigurable to support BsonRepresentation");
}
return localCodec;
}
Aggregations