Skip to content

Commit

Permalink
decode: set all keys under a mapping with custom marshaler decoded
Browse files Browse the repository at this point in the history
This is a naive fix for the issue of custom unmarshal and marking
keys as "decoded". It simply assumes that if there was a custom
unmarshal for a mapping type all keys got handlded by the custom
unmarshal code.

This might be too naive but it seems reasonable and it also seems
we would need a richer interface for a custom unmarshal that gives
access to `MetaData` if we want to be more fine grained.
  • Loading branch information
mvo5 committed Sep 24, 2024
1 parent e4d6f99 commit 70d427d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ func (md *MetaData) unify(data any, rv reflect.Value) error {
if err != nil {
return md.parseErr(err)
}
// assume the Unmarshaler did it's job and decoded all fields
tmap, ok := data.(map[string]any)
if ok {
for key := range tmap {
md.decoded[md.context.add(key).String()] = struct{}{}
}
}
return nil
}
if v, ok := rvi.(encoding.TextUnmarshaler); ok {
Expand Down

0 comments on commit 70d427d

Please sign in to comment.