Skip to content

Prevent custom JsonElement subclasses#1689

Closed
Marcono1234 wants to merge 1 commit into
google:masterfrom
Marcono1234:prevent-json-element-subclasses
Closed

Prevent custom JsonElement subclasses#1689
Marcono1234 wants to merge 1 commit into
google:masterfrom
Marcono1234:prevent-json-element-subclasses

Conversation

@Marcono1234

Copy link
Copy Markdown
Contributor

Adds a package-private constructor to JsonElement to prevent custom subclasses. JsonElement models the JSON data types so there should probably be no need for custom subclasses because the existing JsonElement subclasses cover all of them. Additionally custom subclasses would cause issues during (de-)serialization because the default type adapter does not support them.

However, maybe there are use cases (in unit tests?) where custom subclasses are desired?
Would it be better to only deprecate the public constructor for now?

@inder123

Copy link
Copy Markdown
Collaborator

Yeah, we didn't envision JsonElement to be subclassed. However, at this point in time, it will be a backward incompatible change, and not worth making.

@inder123 inder123 closed this May 18, 2020
@Marcono1234

Marcono1234 commented May 19, 2020

Copy link
Copy Markdown
Contributor Author

Should the public constructor be marked as deprecated at least?

Edit: Nevermind, creating custom subclasses might not actually be that problematic because the default type adapter only calls the JsonElement methods, but does not perform and checks on the class of the object.

@Marcono1234 Marcono1234 deleted the prevent-json-element-subclasses branch May 19, 2020 16:05
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.

3 participants