Skip to content

[JAVA-5203] Support stored nulls for non-primitive fields in Java records#1223

Merged
jyemin merged 4 commits into
mongodb:masterfrom
bulbfreeman:supportNullableInJavaRecordCodec
Oct 23, 2023
Merged

[JAVA-5203] Support stored nulls for non-primitive fields in Java records#1223
jyemin merged 4 commits into
mongodb:masterfrom
bulbfreeman:supportNullableInJavaRecordCodec

Conversation

@bulbfreeman

@bulbfreeman bulbfreeman commented Oct 16, 2023

Copy link
Copy Markdown
Contributor

Why

Same as the issue raised in https://jira.mongodb.org/browse/JAVA-5134, this change implements a mechanism to gracefully handle stored nulls for fields that are annotated with JSR305 @Nullable annotations.

Changes

  • Introduce a boolean field isNullable to RecordCodec.ComponentModel, which is set to true when given field is not primitive.
  • When decoding stored null for a field that is considered nullable in above step, read null in stead of throwing an BsonInvalidOperationException.
  • For any other scenarios, previous codec behaviour is preserved.

Issue ticket

JAVA-5203

@bulbfreeman bulbfreeman changed the title Support stored nulls for nullable fields in Java records [JAVA-5203] Support stored nulls for nullable fields in Java records Oct 16, 2023

@jyemin jyemin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the Jira report and the pull request. I have a change request for you if you're inclined to keep working on this.

Comment thread bson-record-codec/src/main/org/bson/codecs/record/RecordCodec.java Outdated
@bulbfreeman bulbfreeman changed the title [JAVA-5203] Support stored nulls for nullable fields in Java records [JAVA-5203] Support stored nulls for non-premitive fields in Java records Oct 22, 2023
@bulbfreeman bulbfreeman changed the title [JAVA-5203] Support stored nulls for non-premitive fields in Java records [JAVA-5203] Support stored nulls for non-primitive fields in Java records Oct 22, 2023
@bulbfreeman bulbfreeman requested a review from jyemin October 22, 2023 04:06

@jyemin jyemin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more change, please.

Comment thread bson-record-codec/src/main/org/bson/codecs/record/RecordCodec.java Outdated
@bulbfreeman bulbfreeman requested a review from jyemin October 23, 2023 00:10
@jyemin jyemin merged commit 2e12e71 into mongodb:master Oct 23, 2023
@jyemin

jyemin commented Oct 23, 2023

Copy link
Copy Markdown
Collaborator

Thanks for the contribution, @bulbfreeman

@bulbfreeman

Copy link
Copy Markdown
Contributor Author

OOI is there an expected date for the next version release that contains this change? @jyemin

@jyemin

jyemin commented Nov 3, 2023

Copy link
Copy Markdown
Collaborator

Yes, it should be released around Tuesday of next week.

@bulbfreeman

Copy link
Copy Markdown
Contributor Author

Awesome, thanks!

@bulbfreeman bulbfreeman deleted the supportNullableInJavaRecordCodec branch November 7, 2023 06:02
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