Allow ClientContext.Custom unmarshaling for non-string (JSON) values#620
Open
Allow ClientContext.Custom unmarshaling for non-string (JSON) values#620
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #620 +/- ##
==========================================
- Coverage 74.94% 73.99% -0.96%
==========================================
Files 36 36
Lines 1401 1419 +18
==========================================
Hits 1050 1050
- Misses 273 291 +18
Partials 78 78 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
maxday
reviewed
Mar 4, 2026
| if err := json.Unmarshal(v, &s); err == nil { | ||
| cc.Custom[k] = s | ||
| } else { | ||
| cc.Custom[k] = string(v) |
Member
There was a problem hiding this comment.
Maybe you can add a test when JSON parsing is failing? (I think a non-valid JSON will trigger that code path?)
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.
Issue #, if available: -
Description of changes:
When AWS services like Bedrock Agentcore Gateway send nested JSON objects as values in
ClientContext.custom(e.g. propagated headers), the Go Lambda runtime fails with:cannot unmarshal object into Go struct field ClientContext.custom of type string. This blocks all Go Lambda functions used with Agentcore Gateway propagated headers.Root cause
ClientContext.Customismap[string]string, which rejects non-string JSON values duringjson.UnmarshalinparseClientContext()before the handler is ever invoked.How this Fixes that
Add a custom
UnmarshalJSONtoClientContextthat parses Custom values viajson.RawMessage. String values are stored directly (backward compatible) while Non-string values (objects, arrays) are serialized to their JSON string representation instead of failing.Fully backward compatible - no struct signature changes. All existing tests pass.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.