spring-data-mongodb
spring-data-mongodb copied to clipboard
Conversion failed exception from String to bson ObjectId on Mongo calls
Hi,
We are getting following error logged in Dynatrace on all Mongo calls even though app functions normally and we are also unable to see the exception when debugging through IDE:
Exception:
org.springframework.core.convert.ConversionFailedException
Message:
Failed to convert from type [java.lang.String] to type [org.bson.types.ObjectId] for value ''; nested exception is java.lang.IllegalArgumentException: invalid hexadecimal representation of an ObjectId: []
Stacktrace:
org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:47)
org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:191)
org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174)
org.springframework.data.mongodb.core.convert.MongoConverter.convertId(MongoConverter.java:146)
org.springframework.data.mongodb.core.convert.QueryMapper.convertId(QueryMapper.java:636)
org.springframework.data.mongodb.core.convert.QueryMapper.getMappedValue(QueryMapper.java:384)
org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObjectForField(QueryMapper.java:243)
org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:152)
org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:285)
org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:124)
org.springframework.data.mongodb.core.MongoTemplate.doFindOne(MongoTemplate.java:2473)
org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:820)
org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:807)
org.springframework.data.mongodb.core.MongoTemplate$$FastClassBySpringCGLIB$$5a5a6b8.invoke(
How can I go about debugging the issue?
Which version of data-mongodb are you using? There's a guard in the conversion to check validity of a given String representation via ObjectId.isValid.
A complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem would help spot the issue.
We are using spring boot mongo 2.2.0. Is this a known issue or should I go ahead and create a sample project?