Change from JSON Smart to Gson upgrade has breaking changes on serialization and desrialization for jsonObject

Issue #540 closed
Singh Jyoti created an issue

Issue Description:
When generating JWTToken,
Before upgrading to version 9.24+, serialization and de-serialization of a 'JSONObject' containing a class object with a field of type 'Map<String, List>' worked correctly. This was because the getter method was being called during serialization, ensuring proper handling of the data. However, after upgrading to version 9.24+, issues arose where serialization is performed directly on the field type, neglecting to use the getter method for serialization.

Steps to Reproduce:

  1. Define a class with a field of type Map<String, List<String>>.
  2. Ensure the class has appropriate getter and setter methods for the field (In my case it is manipulated to have List<String> type for handling client side use case).
  3. Serialize an instance of this class using JSONObject.
  4. Deserialize the JSON object back into an instance of the class.

Expected Behavior:

  • The getter method for the field should be invoked during serialization, ensuring correct handling of the data.

Actual Behavior:

  • Serialization occurs directly on the field type, bypassing the getter method.

Additional Information:

  • This issue started occurring after upgrading to version 9.24+.
  • for token encryption, using EncryptedJWT class and in the encrypt there is process of getPayload().toByetes() in the Payload class where toString() is called and next it goes to the condition where JSONObjectUtils.toJsonString(jsonObject) is called. further the serialization taking place using Gson lib.
  • JSON to Gson change has the impact. Tried using TypeAdapterFactory class to use custom TypeAdapter but that is not getting invoked/used by gson on execution.

Tech stack:

  • Java Version: 17+
  • Library/Tool Version: Spring 3+
  • OS: any

Comments (5)

  1. Singh Jyoti reporter

    provided examples in the doc, resolved the issue for the mentioned use case. hence closing this.

  2. Log in to comment