Skip to content

Comments

Fix response parsing in shaded builds and modernize test environment (#41, #333)#346

Open
maheshshinde9100 wants to merge 2 commits intorazorpay:masterfrom
maheshshinde9100:master
Open

Fix response parsing in shaded builds and modernize test environment (#41, #333)#346
maheshshinde9100 wants to merge 2 commits intorazorpay:masterfrom
maheshshinde9100:master

Conversation

@maheshshinde9100
Copy link

Problem: Users reported ClassCastExceptions (Issue #41 and #333) when the SDK was re-packaged or "shaded" into a different namespace. This happened because ApiClient.java had a hardcoded "com.razorpay." string, causing reflection to fail when looking up entity classes in different packages. Additionally, the test suite failed on modern Java versions (JDK 17+) due to legacy Mockito configurations.

Changes:

  1. Dynamic Package Resolution: Modified ApiClient.java to use getClass().getPackage().getName() instead of hardcoded strings. This ensures the SDK correctly identifies its own package at runtime, regardless of shading.
  2. Build Modernization: Updated Mockito to 4.11.0 and Jacoco to 0.8.11 to support Java 21+. Configured maven-surefire-plugin with -XX:+EnableDynamicAgentLoading and -Dnet.bytebuddy.experimental=true to allow mocking on newer JVMs.
  3. Test Refactoring: Updated BaseTest.java to replace the deprecated anyObject() matcher with any(). Migrated initMocks() to openMocks() for Mockito 4 compatibility.
  4. Cleanup: Removed duplicate org.json dependency in pom.xml.

Impact:

  • Fixes the "Unable to parse response" error for all developers using custom package structures or build shading.
  • Allows contributors to run the full test suite on modern development environments (JDK 8 through 21).

Verification:

  • Successfully executed mvn clean compile.
  • Passed all 170 unit tests using mvn test on Java 21.

 to throw a clear RazorpayException if an entity class cannot be found, rather than failing with a NullPointerException
- Resolve response parsing errors in shaded/re-packaged environments (razorpay#333)
- Update Mockito and Jacoco for modern JDK compatibility
- Fix deprecated Mockito matchers in BaseTest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant