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

Allow reading json_name field option for proto serialization #2701

Merged
merged 7 commits into from
Jun 22, 2024

Conversation

jabagawee
Copy link
Contributor

Purpose

Closes #2700

Description

Explained in #2700

Checklist

  • New code follows the Google Java Style Guide
    This is automatically checked by mvn verify, but can also be checked on its own using mvn spotless:check.
    Style violations can be fixed using mvn spotless:apply; this can be done in a separate commit to verify that it did not cause undesired changes.
  • If necessary, new public API validates arguments, for example rejects null
  • New public API has Javadoc
    • Javadoc uses @since $next-version$
      ($next-version$ is a special placeholder which is automatically replaced during release)
  • If necessary, new unit tests have been added
    • Assertions in unit tests use Truth, see existing tests
    • No JUnit 3 features are used (such as extending class TestCase)
    • If this pull request fixes a bug, a new test was added for a situation which failed previously and is now fixed
  • mvn clean verify javadoc:jar passes without errors

…` method

In the other commits in this PR, I plan to introduce branching logic inside of
the customization of the serialized name for fields. This change is a pure
refactor that serves to isolate the business logic into a separate commit so as
to make it easier to understand.
Copy link
Member

@eamonnmcmanus eamonnmcmanus left a comment

Choose a reason for hiding this comment

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

Overall this looks great. Just some relatively minor comments.

I'm not sure if @Marcono1234 also wants to weigh in on this review.

* Sets or unsets a flag that, when set, causes the adapter to use the `json_name` field option
* from a proto field for serialization. This `json_name` option is an annotation applied to
* proto fields that cannot be read from the descriptor's options
* (`FieldDescriptor::getOptions`) as it is only available via `FieldDescriptor::getJsonName`.
Copy link
Member

Choose a reason for hiding this comment

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

Here I think you could write {@link FieldDescriptor#getOptions} and {@link FieldDescriptor#getJsonName} since we do import FieldDescriptor.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this sentence about getOptions and getJsonName actually relevant for users of this adapter, or is this an implementation detail and we should omit it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i meant it as a way to explain why users of the adapter expect to see this method here instead of just using the addSerializedNameExtension which might be their initial intuition. i'm cool with removing it if you think it doesn't help.

Copy link
Collaborator

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

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

I'm not sure if @Marcono1234 also wants to weigh in on this review.

I have added just one small review comment. Though I am not that familiar with the Protobuf code here and Protobuf in general, but @jabagawee what you described in the issue sounds reasonable. Thanks for the extensive explanation and tests!

@jabagawee jabagawee requested a review from eamonnmcmanus June 20, 2024 10:01
Copy link
Member

@eamonnmcmanus eamonnmcmanus left a comment

Choose a reason for hiding this comment

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

Looks great, thanks! Just one very minor thing.

@jabagawee jabagawee requested a review from eamonnmcmanus June 22, 2024 01:03
@eamonnmcmanus eamonnmcmanus merged commit 3621e51 into google:main Jun 22, 2024
11 checks passed
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.

Read json_name from protobuf field annotations for serialization and deserialization
3 participants