feat: support json:"-" in mapping (#3521)

This commit is contained in:
Kevin Wan
2023-08-27 16:04:38 +08:00
committed by GitHub
parent 7bbe7de05f
commit 0423313d9b
2 changed files with 120 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ import (
const (
defaultKeyName = "key"
delimiter = '.'
ignoreKey = "-"
)
var (
@@ -437,6 +438,10 @@ func (u *Unmarshaler) processAnonymousField(field reflect.StructField, value ref
return err
}
if key == ignoreKey {
return nil
}
if options.optional() {
return u.processAnonymousFieldOptional(field, value, key, m, fullName)
}
@@ -724,6 +729,10 @@ func (u *Unmarshaler) processNamedField(field reflect.StructField, value reflect
return err
}
if key == ignoreKey {
return nil
}
fullName = join(fullName, key)
if opts != nil && len(opts.EnvVar) > 0 {
envVal := proc.Env(opts.EnvVar)