Throw exception when using classes from other JSON libraries with Gson#2452
Throw exception when using classes from other JSON libraries with Gson#2452Marcono1234 wants to merge 8 commits intogoogle:mainfrom
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.
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.
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
TypeAdapterFactoryimplementations.Checklist
null@since $next-version$(
$next-version$is a special placeholder which is automatically replaced during release)TestCase)mvn clean verify javadoc:jarpasses without errors