Skip to content

Add an option to @Field annotation to control property write rules #3646

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

Conversation

divyajnu08
Copy link
Contributor

…on write

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@divyajnu08
Copy link
Contributor Author

Hi Christoph/Mark

Please find the pull request , I hope it solves the issue , kindly let me know if any comments.
Also I could find only one test case , could you please guide me what are the other test cases need to be changed ?

Thanks

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 9, 2021
@schauder schauder added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels May 17, 2021
@schauder schauder requested a review from mp911de May 17, 2021 14:52
@mp911de
Copy link
Member

mp911de commented Jun 9, 2021

Thanks for your pull request. It goes already in the right direction.

Looking at the code, I'm wondering whether it would actually make sense to represent null handling with an enumeration. omitNull is a negation of what should happen when writing values and from a wording perspective, I don't have a much more descriptive attribute name that would resolve to boolean.

I suggest expressing what should happen if the value is null along the lines of @Field(write=ALWAYS|NON_NULL) accompanied with an enum Field.Write {ALWAYS,NON_NULL} defaulting to NON_NULL. Anything else (omitNull, onNull) could be viewed from both sides, if the property is null or the field in the document is null/non-existent.

@divyajnu08
Copy link
Contributor Author

divyajnu08 commented Jun 12, 2021

Hi Mark

Kindly find the review comments changes updated on the branch.
Let me know if any other change needs to be done.
Now a field will be annotated as @field(write=Field.Write.ALWAYS|NON_NULL) default NON_NULL.
I have created an enum for write rule.

Thanks

@mp911de mp911de changed the title Issue - 3407 Add an option to @Field annoatation to omit null values … Add an option to @Field annotation to control property write rules Jun 14, 2021
@mp911de mp911de added this to the 3.3 M1 (2021.1.0) milestone Jun 14, 2021
@mp911de
Copy link
Member

mp911de commented Jun 14, 2021

Thanks a lot. I pushed a polished variant of the changes to https://github.com/spring-projects/spring-data-mongodb/tree/issue/3407

mp911de pushed a commit that referenced this pull request Jun 14, 2021
…n write.

Properties can be annotated with `@Field(write=…)` to control whether a property with a null value should be included or omitted (default) during conversion in the target Document.

Closes #3407
Original pull request: #3646.
mp911de added a commit that referenced this pull request Jun 14, 2021
Reorder methods and types. Rename MongoPersistentProperty.isOmitNullProperty to writeNullValues. Adapt caching MongoPersistentProperty and add tests.

Tweak Javadoc wording, add author and since tags.

See #3407
Original pull request: #3646.
@mp911de
Copy link
Member

mp911de commented Jun 14, 2021

Thank you for your contribution. That's merged and polished now.

@mp911de mp911de closed this Jun 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an option to @Field annotation to control property write rules [DATAMONGO-2551]
4 participants