fix(json): avoid Gson 2.11+ Strictness to keep runtime compatibility - #228
Open
sls-dev-agent wants to merge 1 commit into
Open
fix(json): avoid Gson 2.11+ Strictness to keep runtime compatibility#228sls-dev-agent wants to merge 1 commit into
sls-dev-agent wants to merge 1 commit into
Conversation
GetLogs threw NoClassDefFoundError: com/google/gson/Strictness when the application classpath resolved an older Gson (< 2.11). Strictness and setStrictness() only exist since Gson 2.11, but the SDK must run against the Gson version the host app provides. Replace setStrictness(STRICT) with the equivalent setLenient(false), which exists in all Gson versions, so the plain (non-shaded) artifact no longer requires Gson 2.11+ at runtime. Bump to 0.6.161-non-fastjson.2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Querying logs on the
non-fastjsonline throws when the host application'sclasspath resolves a Gson older than 2.11:
com.google.gson.StrictnessandJsonReader/JsonWriter.setStrictness(...)wereintroduced in Gson 2.11. The SDK declares Gson 2.13.2, but the plain
(non-shaded) artifact runs against whatever Gson the consuming app provides.
When dependency mediation picks an older Gson (< 2.11), loading
Strictnessfails and every
GetLogscall breaks.Fix
Replace
setStrictness(Strictness.STRICT)with the equivalentsetLenient(false)inJsonTree.parse/JsonTree.write.setLenientexistsin all Gson versions and maps to
Strictness.STRICTin 2.11+, so behavior isunchanged while the runtime floor drops back to the Gson versions the SDK
otherwise already relies on (
setHtmlSafe,setSerializeNulls,ToNumberPolicy). Added@SuppressWarnings("deprecation")sincesetLenientis deprecated in the 2.13.2 the SDK compiles against.
Verification
mvn -B -Dtest='**/*Test,!**/functiontest/**,!ClientTest' test-> 160 tests, 0 failures.mvn -B package -DskipTests-> BUILD SUCCESS (shaded artifact still attaches).GetLogsRequest.getRequestBody()) with Gson2.8.9 forced on the classpath: succeeds after the fix (previously
NoClassDefFoundError).Version
Bumped to
0.6.161-non-fastjson.2and updated the version references inREADME/README_EN and the non-fastjson migration docs.