Skip to content

Use UUID toString representation for UUID values when converting org.bson.Document to json String #3551

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

Closed
wants to merge 4 commits into from

Conversation

christophstrobl
Copy link
Member

@christophstrobl christophstrobl commented Feb 8, 2021

This PR switches the rendering of UUID values to their toString format when converting org.bson.Document to json via the DocumentToStringConverter.

This will move the resulting representation from {"$binary": "QUK3ZihZ9cdhWjTf5TZqrw==", "$type": "03"}
to 480971b0-7160-4120-acd0-6fd6b82418ad.

The conversion only applies on read in cases where an entire Document (like a composite id), is mapped to a String property of the domain model.
Obviously not the most common scenario but one that might easily happen during projections or aggregations.

Relates to: #3546

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.
…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.
Reduce method visibility in tests, enable missed test and format code.
mp911de pushed a commit that referenced this pull request Feb 17, 2021
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.
mp911de pushed a commit that referenced this pull request Feb 17, 2021
…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.
mp911de pushed a commit that referenced this pull request Feb 17, 2021
Reduce method visibility in tests, enable missed test and format code.

Closes #3546.
Original pull request: #3551.
mp911de pushed a commit that referenced this pull request Feb 17, 2021
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.
@mp911de
Copy link
Member

mp911de commented Feb 17, 2021

That's merged now. The UUID fix is backported to 3.1.x.

@mp911de mp911de closed this Feb 17, 2021
@mp911de mp911de deleted the issue/3546 branch February 17, 2021 06:51
@mp911de mp911de added this to the 3.2 M3 (2021.0.0) milestone Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants