fix: handle integer:"string" tags in map values during JSON unmarshal#106
Open
c1-dev-bot[bot] wants to merge 1 commit into
Open
fix: handle integer:"string" tags in map values during JSON unmarshal#106c1-dev-bot[bot] wants to merge 1 commit into
c1-dev-bot[bot] wants to merge 1 commit into
Conversation
The unmarshalValue function's map handling fell through to standard json.Unmarshal for maps with struct value types. Standard json doesn't understand the integer:"string" struct tag, so nested structs like Escalation with string-encoded int64 fields (e.g., expiration: "3600") failed to unmarshal. This fix extends the recursive unmarshal path (already used for complex types like time.Time) to also handle model types (structs), ensuring custom struct tags are respected throughout the entire unmarshal chain. Fixes IGA-731
4 tasks
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.
Summary
Fixes the root cause of the
Escalation.ExpirationJSON unmarshaling failure (IGA-731).The
unmarshalValuefunction's map handling fell through to standardjson.Unmarshalfor maps with struct value types (likemap[string]PolicySteps). Standard json doesn't understand theinteger:"string"struct tag, so nested structs likeEscalationwith string-encoded int64 fields failed with:Root cause
In
pkg/utils/json.go, theunmarshalValuemap case checkedisComplexValueType(time.Time, big.Int, types.Date) to decide whether to use the recursive custom unmarshal path or fall through to standardjson.Unmarshal. Struct types (model types) were not considered "complex", so maps with struct values always used standard json, which doesn't respect custom tags likeinteger:"string".Fix
Extended the condition to also use the recursive unmarshal path when the map value type is a model type (struct). This ensures custom struct tags are respected throughout the entire unmarshal chain, matching how slices/arrays already handle this correctly.
Also added pointer dereferencing in the map recursive path (matching the existing slice/array pattern) to handle cases where the map value is behind a pointer.
Test plan
TestUnmarshalMapWithNestedStringInt64that reproduces the exact error from the issueTestUnmarshalMapWithNestedStringInt64_NumericValuefor string-encoded ints in direct map valuesTestMarshalMapWithNestedStringInt64to verify marshal round-trip