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

issue#2436: Throw exception when registering adapter for Object or JsonElement #2479

Merged
merged 18 commits into from
Oct 3, 2023

Conversation

sachinp97
Copy link
Contributor

Purpose

Closes #2436 to throw IllegalArgumentException for certain Types

Description

Implementation includes a check of Type of an Object class or assignable from JsonElements (i.e. subclass or self).
It seems following use cases of Parameterized Type failed after latest changes.
Additional Fix also excludes Parameterized Type that cover 7 other test cases.

Checklist

  • [ x] New code follows the Google Java Style Guide
  • [ x] If necessary, new public API validates arguments, for example rejects null
  • [ x] New public API has Javadoc
    • [x ] Javadoc uses @since $next-version$
      ($next-version$ is a special placeholder which is automatically replaced during release)
  • [ x] If necessary, new unit tests have been added
    • [ x] Assertions in unit tests use Truth, see existing tests
    • [ x] No JUnit 3 features are used (such as extending class TestCase)
    • [ x] If this pull request fixes a bug, a new test was added for a situation which failed previously and is now fixed
  • [ x] mvn clean verify javadoc:jar passes without errors

Sachin Patil and others added 3 commits August 21, 2023 12:31
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.

Thanks a lot for your changes! They look pretty good.

Could you please edit the title of your pull request? I think GitHub will otherwise use it by default as commit message. For example what about the following?

Throw exception when registering adapter for Object or JsonElement

I have added a few review comments; some are only related to formatting and wording (feel free to use a better wording than what I proposed). Though in general feel free to consider my review comments mostly as suggestions since I am not a direct member of this project.

UserGuide.md Outdated Show resolved Hide resolved
UserGuide.md Outdated Show resolved Hide resolved
gson/src/main/java/com/google/gson/GsonBuilder.java Outdated Show resolved Hide resolved
gson/src/main/java/com/google/gson/GsonBuilder.java Outdated Show resolved Hide resolved
gson/src/main/java/com/google/gson/GsonBuilder.java Outdated Show resolved Hide resolved
gson/src/main/java/com/google/gson/GsonBuilder.java Outdated Show resolved Hide resolved
gson/src/test/java/com/google/gson/GsonBuilderTest.java Outdated Show resolved Hide resolved
gson/src/test/java/com/google/gson/GsonBuilderTest.java Outdated Show resolved Hide resolved
gson/src/test/java/com/google/gson/GsonBuilderTest.java Outdated Show resolved Hide resolved
gson/src/test/java/com/google/gson/GsonBuilderTest.java Outdated Show resolved Hide resolved
@sachinp97
Copy link
Contributor Author

Thanks a lot for your changes! They look pretty good.

Could you please edit the title of your pull request? I think GitHub will otherwise use it by default as commit message. For example what about the following?

Throw exception when registering adapter for Object or JsonElement

I have added a few review comments; some are only related to formatting and wording (feel free to use a better wording than what I proposed). Though in general feel free to consider my review comments mostly as suggestions since I am not a direct member of this project.

@sachinp97 sachinp97 closed this Aug 28, 2023
@sachinp97 sachinp97 reopened this Aug 28, 2023
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.

Thanks for your changes already!

You can change the title of the pull request by clicking the "Edit" button at the top right of the pull request.

Also, there are a few comments still unresolved, unfortunately the GitHub UI has the bad habit of hiding them regardless of whether they are resolved or not...
Hidden conversations screenshot

You can also see all unresolved comments on the "Files changes" tab under "Conversations", see also the GitHub documentation.

@google google deleted a comment from Crazyfortiff Aug 30, 2023
@sachinp97 sachinp97 changed the title Feature/issue#2436 enhancement issue#2436: Throw exception when registering adapter for Object or JsonElement Sep 7, 2023
@sachinp97
Copy link
Contributor Author

@Marcono1234 @eamonnmcmanus , I have pushed the changes as per review.
Please have a final review before the merge.

Thanks for great review and comments!

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 is looking good. I'm running it against all of Google's internal tests just to make sure there are no unexpected problems.

A couple of small things. And also, could you update the CL with the latest changes from HEAD?

gson/src/main/java/com/google/gson/GsonBuilder.java Outdated Show resolved Hide resolved
gson/src/main/java/com/google/gson/GsonBuilder.java Outdated Show resolved Hide resolved
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.

Thank you very much for your changes!

In addition to Éamonn's comments I added a few small additional comments but besides that the pull request looks fine to me as well.
If you want you can also directly apply the suggested changes from the GitHub UI. (Also don't worry too much about the commit messages; the commits will be squashed into a single commit here anyways when merged.)

gson/src/main/java/com/google/gson/GsonBuilder.java Outdated Show resolved Hide resolved
gson/src/test/java/com/google/gson/GsonBuilderTest.java Outdated Show resolved Hide resolved
gson/src/test/java/com/google/gson/GsonBuilderTest.java Outdated Show resolved Hide resolved
@sachinp97
Copy link
Contributor Author

Thanks @eamonnmcmanus and @Marcono1234 again for final reviews, please confirm so I can merge and close it.

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.

If @Marcono1234 is also OK with these changes we can merge them.

@sachinp97
Copy link
Contributor Author

I don't have a write access to this repository, @Marcono1234 can you suggest if we are good and anyone can merge the PR?

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.

Yes for me this is fine as well, thanks a lot for your work on this!

@eamonnmcmanus eamonnmcmanus merged commit 0109f45 into google:main Oct 3, 2023
9 checks passed
tibor-universe pushed a commit to getuniverse/gson that referenced this pull request Sep 14, 2024
…onElement (google#2479)

* Code changes and tests for google#2436 to throw exception when trying to register adapter for Object or JsonElement

* google#2436 - Updates to User guide & comments to indicate exception cases and fix for 7 test cases of Parameterized Type

* google#2436 - Fixes as per the review comments.

* google#2436 - Refactored as per latest review comments + throwing error message.

* google#2436 - added a clarifying comment in a positive test case.

* google#2436 - formatting and minor changes as per review.

* Update gson/src/main/java/com/google/gson/GsonBuilder.java

Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>

* Update gson/src/test/java/com/google/gson/GsonBuilderTest.java

Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>

* Update gson/src/test/java/com/google/gson/GsonBuilderTest.java

Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>

---------

Co-authored-by: Sachin Patil <sachin.patil2@capitalone.com>
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
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.

GsonBuilder should throw exception when trying to register adapter for Object or JsonElement
3 participants