Search in sources :

Example 1 with RepresentationConfigurable

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;
}
Also used : BsonType(org.bson.BsonType) CodecConfigurationException(org.bson.codecs.configuration.CodecConfigurationException) RepresentationConfigurable(org.bson.codecs.RepresentationConfigurable)

Aggregations

BsonType (org.bson.BsonType)1 RepresentationConfigurable (org.bson.codecs.RepresentationConfigurable)1 CodecConfigurationException (org.bson.codecs.configuration.CodecConfigurationException)1