From 70d427dc9782b446329735431be96369a22c4eaa Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 24 Sep 2024 16:22:53 +0200 Subject: [PATCH] decode: set all keys under a mapping with custom marshaler decoded 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. --- decode.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/decode.go b/decode.go index c05a0b7..afdd018 100644 --- a/decode.go +++ b/decode.go @@ -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 {