Description
Sylvain LAURENT opened DATAMONGO-1439 and commented
Currently (as of 1.8.2) when reading an "undefined" value from mongo, we have this exception :
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.bson.BsonUndefined] to type [java.math.BigDecimal]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:313) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:195) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:176) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getPotentiallyConvertedSimpleRead(MappingMongoConverter.java:822) ~[spring-data-mongodb-1.8.2.RELEASE.jar:na]
It would be nice to have a way of converting sunch BsonUndefined to null out of the box.
For my own usage, I created this converter factory :
@ReadingConverter
public class BsonUndefinedToNullObjectConverterFactory implements ConverterFactory<BsonUndefined, @Nullable Object> {
@Override
public <T extends @Nullable Object> Converter<BsonUndefined, T> getConverter(Class<T> targetType) {
return o -> null;
}
}
It works, with the small glitch of this warning which I think is not correct for this situation :
WARN o.s.d.m.c.convert.CustomConversions - - Registering converter from class org.bson.BsonUndefined to class java.lang.Object as reading converter although it doesn't convert from a Mongo supported type! You might wanna check you annotation setup at the converter implementation.
Affects: 1.8.4 (Gosling SR4)
1 votes, 2 watchers