You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: support autoType when keyType is String for Map typed reader - #7964
When deserializing a Map with keyType = String, the inner @type field was ignored even if SupportAutoType feature was enabled or ContextAutoTypeBeforeHandler was provided.
The keyType == String.class branch missed the auto-type condition check which already existed in the else branch. This change aligns the condition so auto-type works consistently for String-key typed maps.
Summary of your change
Add the missing auto-type check condition in ObjectReaderImplMapTyped for the keyType == String.class path: || jsonReader.getContext().getContextAutoTypeBeforeHandler() != null
Add a test case to verify auto-type deserialization works for typed Map with String key.
Please indicate you've done the following:
Made sure tests are passing and test coverage is added if needed.
1. Use the helper the project already has. The first commit wrote the check by hand: isEnabled(SupportAutoType) || getContextAutoTypeBeforeHandler() != null. JSONReader already has isSupportAutoTypeOrHandler(long features) for exactly this, and ObjectReaderAdapter calls it. Using it keeps the rule in one place.
There is also a small semantic reason. The old line tested contextFeatures, which is the context features OR the features argument passed in. isEnabled reads only the context features, so the hand-written version describes a slightly narrower rule than before. I looked for a way to hit that gap and could not find one a user can reach: @JSONField has no features attribute in this version, so there is no per-field switch. So I am not calling it a bug, just a place where the shorter form does not say the same thing as the old code.
2. Cover the feature path. The first commit only tested the autoTypeFilter route. Auto type also turns on through the SupportAutoType feature alone, so there is now a second test for that.
Evidence the fix does something.
On 460d2e4b4 (upstream main) with the new test: JSONException: expect ':', but 44, offset 21. The reader treats the inner @type as a normal key and then chokes on the comma.
On 5656dbc99: both cases parse, varsMap is a LinkedHashMap.
One thing outside my control: the CI run on this PR is at action_required, so no job has run yet. A maintainer needs to approve the workflow before the matrix means anything.
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
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.
What this PR does / why we need it?
When deserializing a Map with
keyType = String, the inner@typefield was ignored even ifSupportAutoTypefeature was enabled orContextAutoTypeBeforeHandlerwas provided.The
keyType == String.classbranch missed the auto-type condition check which already existed in the else branch. This change aligns the condition so auto-type works consistently for String-key typed maps.Summary of your change
Add the missing auto-type check condition in
ObjectReaderImplMapTypedfor thekeyType == String.classpath:|| jsonReader.getContext().getContextAutoTypeBeforeHandler() != nullAdd a test case to verify auto-type deserialization works for typed Map with String key.
Please indicate you've done the following: