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

Move enum and JsonElement adapter classes to separate class files #2727

Merged

Conversation

Marcono1234
Copy link
Collaborator

@Marcono1234 Marcono1234 commented Aug 11, 2024

Purpose

Make internal code easier to read and maintain by moving some nested classes inside TypeAdapters to separate class files.

Description

Their implementation is complex enough to probably justify having them in their own class files, to make maintaining them easier. For the users this should not be noticeable since these classes are still in the Gson internal package.

I have also added a few comments to the implementations.

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

Their implementation is complex enough to probably justify having them in
their own class files, to make maintaining them easier.
For the users this should not be noticeable since these classes are still
in the Gson internal package.
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.

I like this a lot. I'm certainly not a fan of giant anonymous classes! However, even though people shouldn't be accessing the .internal. APIs, you just know they do. Here is an example. It doesn't cost much to keep the public fields in TypeAdapters and just change how they get their values. So I think we should do that.

Note: `JSON_ELEMENT_FACTORY` seems to be rarely used, therefore this has not
been added back.
@Marcono1234
Copy link
Collaborator Author

Marcono1234 commented Aug 13, 2024

Good point, I forgot to consider that. I added back JSON_ELEMENT and ENUM_FACTORY, but not JSON_ELEMENT_FACTORY because it seems to be rarely used (most of these seems to be forks, or decompiled apps). Is that ok?

@eamonnmcmanus
Copy link
Member

I think we might as well just keep all the public fields? It doesn't cost much.

@Marcono1234
Copy link
Collaborator Author

Ok, I have added JSON_ELEMENT_FACTORY back as well. I was a bit worried that we keep accumulating @Deprecated fields and methods in Gson's internal code this way, but so far it is not that bad yet.

@eamonnmcmanus eamonnmcmanus merged commit 93596da into google:main Aug 17, 2024
11 checks passed
@Marcono1234 Marcono1234 deleted the marcono1234/separate-adapter-classes branch August 17, 2024 22:59
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.

2 participants