fix: StringToAny to Boolean rejects TRUE/True/T/Y spellings, for issue #7842 - #7848
Open
WLLTB wants to merge 1 commit into
Open
fix: StringToAny to Boolean rejects TRUE/True/T/Y spellings, for issue #7842#7848WLLTB wants to merge 1 commit into
WLLTB wants to merge 1 commit into
Conversation
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.
Fixes #7842
What this PR does / why we need it?
TypeUtils.castToJavaBean("TRUE", Boolean.class)returnsfalse. All String-to-Boolean conversions go throughStringToAny, whose boolean branch only accepted lowercase"true", whileToBoolean(used for every other source type) acceptsTRUE/True/T/Y/YESand friends — so the String source type could never reach the richer logic.Summary of your change
StringToAny: boolean branch now accepts"true"/"T"/"Y"case-insensitively (matchingToBoolean's single-letter set and fastjson1'scastToBooleanspellings); unrecognized strings keep the existing lenientFALSEfallback instead of throwing, since this converter is shared byJSONObject/JSONArray/JSONPath/list conversion paths.core/src/test/java/com/alibaba/fastjson2/issues_7800/Issue7842.java.Note:
"1"is deliberately left asfalse—JSONObjectTest.test_invokepins that behavior, andToBooleandoesn't accept"1"either. Happy to flip it if maintainers prefer fastjson1'scastToBooleansemantics there.Verified: core 7992 passed (standard +
-Dfastjson2.creator=reflect), fastjson1-compatible 1355 passed, rootvalidateclean.Please indicate you've done the following: