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
mergify bot added a commit to ArcadeData/arcadedb that referenced this pull request Feb 3, 2025
…ip ci]

Bumps [com.google.code.gson:gson](https://github.com/google/gson) from 2.11.0 to 2.12.1.
Release notes

*Sourced from [com.google.code.gson:gson's releases](https://github.com/google/gson/releases).*

> Gson 2.11.1
> -----------
> 
> The only difference between this release and 2.11.0 is that OSGi declarations in the Gson jar now specify that `com.google.errorprone.annotations` is an optional dependency, not a required one. If you do not use OSGi then there is no effective change.
> 
> Gson 2.12.0
> -----------
> 
> What's Changed
> --------------
> 
> The biggest change is that we no longer support Java 7. People who still need to run on Java 7 will need to use an earlier version of Gson.
> 
> Other changes:
> 
> * Allow registering adapters for `JsonElement` again by [`@​Marcono1234`](https://github.com/Marcono1234) in [google/gson#2789](https://redirect.github.com/google/gson/pull/2789)
> * Add nesting limit for `JsonReader` by [`@​Marcono1234`](https://github.com/Marcono1234) in [google/gson#2588](https://redirect.github.com/google/gson/pull/2588)
> * Add `@CheckReturnValue` to our packages. by [`@​cpovirk`](https://github.com/cpovirk) in [google/gson#2693](https://redirect.github.com/google/gson/pull/2693)
> * Add NullSafeTypeAdapter to prevent TypeAdapter.nullSafe() from returning nested null-safe type adapters ([#2729](https://redirect.github.com/google/gson/issues/2729)) by [`@​lyubomyr-shaydariv`](https://github.com/lyubomyr-shaydariv) in [google/gson#2731](https://redirect.github.com/google/gson/pull/2731)
> * Support Properties subclasses in GsonTypes.getMapKeyAndValueTypes by [`@​panic08`](https://github.com/panic08) in [google/gson#2758](https://redirect.github.com/google/gson/pull/2758)
> * Enforce rawType to be a Class in ParameterizedTypeImpl by [`@​panic08`](https://github.com/panic08) in [google/gson#2759](https://redirect.github.com/google/gson/pull/2759)
> * Remove `AccessController` usage for enum adapter by [`@​Marcono1234`](https://github.com/Marcono1234) in [google/gson#2704](https://redirect.github.com/google/gson/pull/2704)
> * Fix typeArguments array not being cloned when resolving ParameterizedType with changed owner by [`@​TBlueF`](https://github.com/TBlueF) in [google/gson#2706](https://redirect.github.com/google/gson/pull/2706)
> * Remove duplicated declaration of required OSGi execution environment by [`@​HannesWell`](https://github.com/HannesWell) in [google/gson#2711](https://redirect.github.com/google/gson/pull/2711)
> * Move bnd.bnd file configuration into 'bnd' element of bnd-maven-plugin by [`@​HannesWell`](https://github.com/HannesWell) in [google/gson#2712](https://redirect.github.com/google/gson/pull/2712)
> * Move enum and `JsonElement` adapter classes to separate class files by [`@​Marcono1234`](https://github.com/Marcono1234) in [google/gson#2727](https://redirect.github.com/google/gson/pull/2727)
> * EnumTypeAdapter constructor optimization by [`@​esaulpaugh`](https://github.com/esaulpaugh) in [google/gson#2734](https://redirect.github.com/google/gson/pull/2734)
> * OSGi / bnd: Remove the self-Import of gson.annotations by [`@​chrisrueger`](https://github.com/chrisrueger) in [google/gson#2735](https://redirect.github.com/google/gson/pull/2735)
> 
> New Contributors
> ----------------
> 
> * [`@​cpovirk`](https://github.com/cpovirk) made their first contribution in [google/gson#2693](https://redirect.github.com/google/gson/pull/2693)
> * [`@​jabagawee`](https://github.com/jabagawee) made their first contribution in [google/gson#2701](https://redirect.github.com/google/gson/pull/2701)
> * [`@​TBlueF`](https://github.com/TBlueF) made their first contribution in [google/gson#2706](https://redirect.github.com/google/gson/pull/2706)
> * [`@​HannesWell`](https://github.com/HannesWell) made their first contribution in [google/gson#2711](https://redirect.github.com/google/gson/pull/2711)
> * [`@​esaulpaugh`](https://github.com/esaulpaugh) made their first contribution in [google/gson#2734](https://redirect.github.com/google/gson/pull/2734)
> * [`@​chrisrueger`](https://github.com/chrisrueger) made their first contribution in [google/gson#2735](https://redirect.github.com/google/gson/pull/2735)
> * [`@​panic08`](https://github.com/panic08) made their first contribution in [google/gson#2756](https://redirect.github.com/google/gson/pull/2756)
> 
> **Full Changelog**: <google/gson@gson-parent-2.11.0...gson-parent-2.12.0>


Commits

* [`29e3d1d`](google/gson@29e3d1d) [maven-release-plugin] prepare release gson-parent-2.12.1
* [`be456cf`](google/gson@be456cf) Make the import of com.google.errorprone optional ([#2795](https://redirect.github.com/google/gson/issues/2795))
* [`b2e26fa`](google/gson@b2e26fa) Bump the github-actions group with 3 updates ([#2785](https://redirect.github.com/google/gson/issues/2785))
* [`10bdd6d`](google/gson@10bdd6d) Simplify collection type adapters slightly. ([#2791](https://redirect.github.com/google/gson/issues/2791))
* [`ab9c54f`](google/gson@ab9c54f) [maven-release-plugin] prepare for next development iteration
* [`aaf7a12`](google/gson@aaf7a12) [maven-release-plugin] prepare release gson-parent-2.12.0
* [`a2b1c3c`](google/gson@a2b1c3c) Allow registering adapters for `JsonElement` again ([#2789](https://redirect.github.com/google/gson/issues/2789))
* [`e5dce84`](google/gson@e5dce84) Bump the maven group with 8 updates ([#2784](https://redirect.github.com/google/gson/issues/2784))
* [`84e5f16`](google/gson@84e5f16) Bump the maven group with 7 updates ([#2777](https://redirect.github.com/google/gson/issues/2777))
* [`9f3e577`](google/gson@9f3e577) Bump the github-actions group with 2 updates ([#2778](https://redirect.github.com/google/gson/issues/2778))
* Additional commits viewable in [compare view](google/gson@gson-parent-2.11.0...gson-parent-2.12.1)

  

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=com.google.code.gson:gson&package-manager=maven&previous-version=2.11.0&new-version=2.12.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
Dependabot commands and options
  

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show  ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
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