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

Only create one BoundField instance per field in ReflectiveTypeAdapterFactory #2440

Merged

Conversation

Marcono1234
Copy link
Collaborator

Purpose

Fixes #2438

Description

Instead of creating a BoundField for every possible name of a field (for @SerializedName usage) and then storing for that BoundField whether it is serialized or deserialized, instead only create one BoundField and then have a separate Map<String, BoundField> for deserialized fields, and a separate List<BoundField> for serialized fields.

This shouldn't cause any changes visible to the user.

Not sure if this implementation is clean enough; feedback is appreciated!

Checklist

  • New code follows the Google Java Style Guide
  • 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

…rFactory

Instead of creating a BoundField for every possible name of a field (for
SerializedName usage) and then storing for that BoundField whether it is
serialized or deserialized, instead only create one BoundField and then have
a separate Map<String, BoundField> for deserialized fields, and a separate
List<BoundField> for serialized fields.
@Marcono1234 Marcono1234 force-pushed the marcono1234/refactor-BoundField-creation branch from 9819be8 to 8a5d6ea Compare July 20, 2023 22:22
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.

This looks great. I ran it past Google's tests and had no problems. (Except one place where people were accessing the internals of ReflectiveTypeAdapterFactory via reflection. I'll update that at the same time as I import these changes.)

Just one trivial request.

@eamonnmcmanus eamonnmcmanus merged commit e7cf5c4 into google:main Sep 30, 2023
9 checks passed
@Marcono1234 Marcono1234 deleted the marcono1234/refactor-BoundField-creation branch September 30, 2023 20:33
tibor-universe pushed a commit to getuniverse/gson that referenced this pull request Sep 14, 2024
…pterFactory` (google#2440)

* Only create one BoundField instance per field in ReflectiveTypeAdapterFactory

Instead of creating a BoundField for every possible name of a field (for
SerializedName usage) and then storing for that BoundField whether it is
serialized or deserialized, instead only create one BoundField and then have
a separate Map<String, BoundField> for deserialized fields, and a separate
List<BoundField> for serialized fields.

* Fix indentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants