-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Throw exception when using classes from other JSON libraries with Gson #2452
base: main
Are you sure you want to change the base?
Throw exception when using classes from other JSON libraries with Gson #2452
Conversation
<artifactId>json</artifactId> | ||
<!-- Uses an ancient version because it matches roughly the API of the same classes from Android | ||
See also https://stackoverflow.com/q/39564936 --> | ||
<version>20090211</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not very happy about using such an outdated test dependency, especially because that version does not even have source code or Javadoc available, but it matches the Android API closely and therefore makes it easier to verify that the code in the JsonOrgInteropTest
test class (which is also shown in the Troubleshooting Guide) compiles for Android as well.
} | ||
} | ||
|
||
private static class JSONArraySubject extends JsonOrgBaseSubject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe having these custom Truth Subject
classes is a bit exaggerated, and they might not follow Truth best practices (feedback is welcome). Though on the other hand they make comparison of JSONArray
and JSONObject
easier.
The code suggested in the troubleshooting guide to keep backward compatibility with the previous reflection-based output for If necessary we could possibly consider adding a system property for now which still allows users to use reflection on those classes, but mention that the system property will be removed in future Gson versions. |
Purpose
Resolves #2445
Description
See #2445 for the rationale.
With these changes an exception is thrown when users try to serialize or deserialize unsupported JSON classes from other libraries.
Currently detected libraries:
org.json.JSONArray
,org.json.JSONObject
)Also a new Troubleshooting Guide entry has been added explaining the issue and for JSON-java / Android suggesting backward compatible
TypeAdapterFactory
implementations.Checklist
null
@since $next-version$
(
$next-version$
is a special placeholder which is automatically replaced during release)TestCase
)mvn clean verify javadoc:jar
passes without errors