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

Document that other JVM languages are not fully supported #2666

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

Conversation

Marcono1234
Copy link
Collaborator

@Marcono1234 Marcono1234 commented Apr 6, 2024

Purpose

Document that other JVM languages are not fully supported

Description

Gson's main focus is on Java. Because Gson uses reflection it works in many cases also for other JVM languages such as Kotlin or Scala, but because it does not explicitly consider these languages, language-specific features which do not exist in Java don't work properly. See for example issues with kotlin Issues concerning the use of Gson with Kotlin label.

Therefore this pull request adds a warning to prevent new users from investing a lot of time to use Gson with these languages just to notice in the end that it is not properly working or error-prone.
If at some point in the future Gson properly supports other JVM languages, the warning can be removed again. But (at least to me) it seems a bit unlikely that this will ever happen, because:

  • Gson is in maintenance mode
  • Additional code and dependencies (or a separate module) is needed to account for these language-specific features
  • It could cause confusion if new API is added to Gson which is only relevant for other JVM languages but not Java (and the other way around)
  • There are already mature other JSON libraries for these languages, so Gson would then just compete with them

Actually this limitation mostly (or only) applies to reflection-based serialization and deserialization. Using only custom TypeAdapters, JsonElement (and subclasses) or JsonReader and JsonWriter will probably work fine. However, explaining this might be a bit verbose, and most likely using reflection-based serialization is the most common use case. And even if users initially only use the non-reflective features, they might in the future use them and would then either have to migrate or mix multiple JSON libraries which often does not work that well.

Feedback regarding the wording and where to document this (e.g. not in the README but instead somewhere else) is appreciated. I did not want to explicitly list the other JSON libraries because there are multiple and to not endorse specific ones when there are other ones which might be better suited for the specific use case of the user, or if new libraries emerge in the future.

@Marcono1234 Marcono1234 added the kotlin Issues concerning the use of Gson with Kotlin label Apr 6, 2024
@@ -8,6 +8,10 @@ There are a few open-source projects that can convert Java objects to JSON. Howe
> [!NOTE]\
> Gson is currently in maintenance mode; existing bugs will be fixed, but large new features will likely not be added. If you want to add a new feature, please first search for existing GitHub issues, or create a new one to discuss the feature and get feedback.

> [!IMPORTANT]\
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This uses the GitHub-specific alert syntax, similar to the > [!NOTE] above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kotlin Issues concerning the use of Gson with Kotlin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant