Skip to content

Commit e78b7e8

Browse files
committed
Merge branch 'master' of https://github.com/json-iterator/go
2 parents 945d1aa + c3ed5e8 commit e78b7e8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

feature_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Config struct {
1818
SortMapKeys bool
1919
UseNumber bool
2020
TagKey string
21+
OnlyTaggedField bool
2122
ValidateJsonRawMessage bool
2223
ObjectFieldMustBeSimpleString bool
2324
}
@@ -27,6 +28,7 @@ type frozenConfig struct {
2728
sortMapKeys bool
2829
indentionStep int
2930
objectFieldMustBeSimpleString bool
31+
onlyTaggedField bool
3032
decoderCache unsafe.Pointer
3133
encoderCache unsafe.Pointer
3234
extensions []Extension
@@ -77,6 +79,7 @@ func (cfg Config) Froze() API {
7779
sortMapKeys: cfg.SortMapKeys,
7880
indentionStep: cfg.IndentionStep,
7981
objectFieldMustBeSimpleString: cfg.ObjectFieldMustBeSimpleString,
82+
onlyTaggedField: cfg.OnlyTaggedField,
8083
streamPool: make(chan *Stream, 16),
8184
iteratorPool: make(chan *Iterator, 16),
8285
}

feature_reflect_extension.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,10 @@ func describeStruct(cfg *frozenConfig, prefix string, typ reflect.Type) *StructD
245245
bindings := []*Binding{}
246246
for i := 0; i < typ.NumField(); i++ {
247247
field := typ.Field(i)
248-
tag := field.Tag.Get(cfg.getTagKey())
248+
tag, hastag := field.Tag.Lookup(cfg.getTagKey())
249+
if cfg.onlyTaggedField && !hastag {
250+
continue
251+
}
249252
tagParts := strings.Split(tag, ",")
250253
if tag == "-" {
251254
continue

0 commit comments

Comments
 (0)