1
0
mirror of https://github.com/json-iterator/go.git synced 2025-03-29 21:20:52 +02:00

Merge pull request #222 from neverlee/mydev

加入一个OnlyTaggedField选项
This commit is contained in:
Tao Wen 2018-01-09 18:30:25 +08:00 committed by GitHub
commit c3ed5e85e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -18,6 +18,7 @@ type Config struct {
SortMapKeys bool
UseNumber bool
TagKey string
OnlyTaggedField bool
ValidateJsonRawMessage bool
ObjectFieldMustBeSimpleString bool
}
@ -27,6 +28,7 @@ type frozenConfig struct {
sortMapKeys bool
indentionStep int
objectFieldMustBeSimpleString bool
onlyTaggedField bool
decoderCache unsafe.Pointer
encoderCache unsafe.Pointer
extensions []Extension
@ -77,6 +79,7 @@ func (cfg Config) Froze() API {
sortMapKeys: cfg.SortMapKeys,
indentionStep: cfg.IndentionStep,
objectFieldMustBeSimpleString: cfg.ObjectFieldMustBeSimpleString,
onlyTaggedField: cfg.OnlyTaggedField,
streamPool: make(chan *Stream, 16),
iteratorPool: make(chan *Iterator, 16),
}

View File

@ -245,7 +245,10 @@ func describeStruct(cfg *frozenConfig, prefix string, typ reflect.Type) *StructD
bindings := []*Binding{}
for i := 0; i < typ.NumField(); i++ {
field := typ.Field(i)
tag := field.Tag.Get(cfg.getTagKey())
tag, hastag := field.Tag.Lookup(cfg.getTagKey())
if cfg.onlyTaggedField && !hastag {
continue
}
tagParts := strings.Split(tag, ",")
if tag == "-" {
continue