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

Add Gson method for creating new instances (using InstanceCreators) #1968

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Marcono1234
Copy link
Collaborator

@Marcono1234 Marcono1234 commented Sep 17, 2021

Adds the method Gson.createInstance(TypeToken) exposing ConstructorConstructor's functionality.
This allows custom TypeAdapterFactories to easily create new instances which can be useful for example for custom collection-like types or for custom reflection based adapters which want to support @JsonAdapter, see #1794 (comment).

Might resolve or relate to #537, though from its description it is not completely clear what that issue was proposing and the attached patch does not seem to be available anymore.

@google-cla google-cla bot added the cla: yes label Sep 17, 2021
Comment on lines +1022 to +1023
// TODO: Specify thrown exception type; but ConstructorConstructor currently uses
// RuntimeException instead of specific exception
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if this can be resolved in a reasonable way yet.
Ideally in the future Gson's exception hierarchy should be refactored. There are exception types missing, such as for this case or when serialization fails (Gson's exceptions all seem to be related to deserialization), which currently leads to usage of RuntimeException.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant