Skip to content
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

Add support for omitting defaults #269

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fmeum
Copy link

@fmeum fmeum commented Aug 16, 2023

If a class is annotated with the new @OmitDefaults annotation, which requires a builder, then all properties that have a value set by the default builder method and correspond to a getter function on the builder have their value omitted from the serialized JSON if it matches the default one.

If a class is annotated with the new `@OmitDefaults` annotation, which
requires a builder, then all properties that have a value set by the
default builder method and correspond to a getter function on the
builder have their value omitted from the serialized JSON if it matches
the default one.
@fmeum
Copy link
Author

fmeum commented Aug 16, 2023

@rharter A bit of context: This came up over at Bazel while building some kind of generic package manager that heavily relies on auto-value-gson to generate its lockfile. Since we also need to hash the contents of these lockfiles and want them to remain stable as we add new fields, we need some way to omit fields that are at their default values.

The approach taken in this PR felt natural to me, but I am open to suggestions to do this differently.

I also think that #268 could be solved by this as well in a backwards compatible way: Omit null-valued properties if and only if the class is annotated with @OmitDefaults (and lift the requirement to have a Builder subclass). Let me know what you think, happy to make the changes to resolve this related issue.

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.

1 participant