Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an optional way to convert from BsonUndefined to null [DATAMONGO-1439] #2350

Closed
spring-projects-issues opened this issue May 27, 2016 · 1 comment
Assignees
Labels
in: mapping Mapping and conversion infrastructure type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

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

@jkjsanthosh
Copy link

jkjsanthosh commented Nov 6, 2022

@a-cordier why do you close this issue, this converter support has to be added in spring data mongodb by default right?
I have see your team wrote a custom converter and registered in mongomappingconverter. But that is temporary solution only right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: mapping Mapping and conversion infrastructure type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants