-
Notifications
You must be signed in to change notification settings - Fork 1.1k
org.bson.codecs.configuration.CodecConfigurationException: The uuidRepresentation has not been specified, so the UUID cannot be encoded. #3546
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
Comments
Having a look at the example the error in |
Thanks for the quick response, Christoph! But the test still blowing up :( |
It seems the uuidRepresentation setting is not picked up by the registry. MongoClientSettings clientSettings = MongoClientSettings.builder().uuidRepresentation(UuidRepresentation.JAVA_LEGACY).build();
CodecRegistry codecRegistry = MongoClients.create(clientSettings).getDatabase("test").getCodecRegistry();
aggregationBlock.toJson(codecRegistry.get(org.bson.Document.class)) You might want to report this issue to the MongoDB Drivers Team |
@christophstrobl is there a way to customize DocumentCodec uuidRepresentation through spring-context/beans? |
I found that when the encoder try to write the value for a document that has UUID property the next code has executed:
In case when we write UUID value registry.get() method returned UuidCodec with default Unspecified UUID representation...
Therefore we always will have such error :( |
Eventually, I found the cause… So the problem is that in Spring Data 3.x when I use group like:
I will have as result the next aggregation:
I have CodecConfigurationExcpetion because _id: [FieldOne: X, FieldTwo: Y, FieldThree: Z] can not be cast to UUID… Composite ids from Aggregation.Group() are no longer mapped to their respective fields. Could you please provide some info on how to deal with such a case, and is there any way to reverse/configure this? |
I'm afraid I do not quite understand the last comment on composite ids. |
This commit makes sure to use an Encoder having UuidRepresentation set when calling org.bson.Document#toJson, preventing CodecConfigurationException from being raised. Future versions will make sure the UUID string representation matches the Java default one. Closes #3546. Original pull request: #3551.
…to a json String. This commit switches the rendering of UUID values to their toString format when printing org.bson.Document to json via the DocumentToString converter. This will move the resulting representation from {"$binary": "QUK3ZihZ9cdhWjTf5TZqrw==", "$type": "03"} to 480971b0-7160-4120-acd0-6fd6b82418ad which is the more natural variant within Java applications. The conversion only applies on read in cases where an entire document eg. a composite id, is mapped to a String property of the domain model. Closes #3546. Original pull request: #3551.
This commit makes sure to use an Encoder having UuidRepresentation set when calling org.bson.Document#toJson, preventing CodecConfigurationException from being raised. Future versions will make sure the UUID string representation matches the Java default one. Closes #3546. Original pull request: #3551.
I'm trying to upgrade the version of spring boot from 2.3.0 to 2.4.0. After updates I've tried to run my unit tests and got codec exception 😞
An example of a simplified project: https://github.com/airtaste/example/tree/master
Also, I've tried to use Spring Boot property spring.data.mongodb.uuid-representation and set it to 'standard', but the error still occurred. Furthermore, I tried to customize MongoClientSettings to include UuidRepresentation.STANDARD codec registry. Ineffectually.
It's a very odd issue.
Thanks in advance!
The text was updated successfully, but these errors were encountered: