Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions reflect_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ func processTags(structDescriptor *StructDescriptor, cfg *frozenConfig) {
if binding.Field.Type().Kind() == reflect.String {
binding.Decoder = &stringModeStringDecoder{binding.Decoder, cfg}
binding.Encoder = &stringModeStringEncoder{binding.Encoder, cfg}
} else {
binding.Decoder = &stringModeNumberDecoder{binding.Decoder}
binding.Encoder = &stringModeNumberEncoder{binding.Encoder}
} else if binding.Field.Type().Kind() != reflect.Slice && binding.Field.Type().Kind() != reflect.Map{
binding.Decoder = &stringModeNonStringDecoder{binding.Decoder}
binding.Encoder = &stringModeNonStringEncoder{binding.Encoder}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions reflect_struct_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,14 +1026,14 @@ func (decoder *stringModeStringDecoder) Decode(ptr unsafe.Pointer, iter *Iterato
*((*string)(ptr)) = tempIter.ReadString()
}

type stringModeNumberDecoder struct {
type stringModeNonStringDecoder struct {
elemDecoder ValDecoder
}

func (decoder *stringModeNumberDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
func (decoder *stringModeNonStringDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
c := iter.nextToken()
if c != '"' {
iter.ReportError("stringModeNumberDecoder", `expect ", but found `+string([]byte{c}))
iter.ReportError("stringModeNonStringDecoder", `expect ", but found `+string([]byte{c}))
return
}
decoder.elemDecoder.Decode(ptr, iter)
Expand All @@ -1042,7 +1042,7 @@ func (decoder *stringModeNumberDecoder) Decode(ptr unsafe.Pointer, iter *Iterato
}
c = iter.readByte()
if c != '"' {
iter.ReportError("stringModeNumberDecoder", `expect ", but found `+string([]byte{c}))
iter.ReportError("stringModeNonStringDecoder", `expect ", but found `+string([]byte{c}))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it needs a testcase to cover these new added lines to avoid the coverage diff reported by codecov.

return
}
}
6 changes: 3 additions & 3 deletions reflect_struct_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,17 @@ func (encoder *emptyStructEncoder) IsEmpty(ptr unsafe.Pointer) bool {
return false
}

type stringModeNumberEncoder struct {
type stringModeNonStringEncoder struct {
elemEncoder ValEncoder
}

func (encoder *stringModeNumberEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
func (encoder *stringModeNonStringEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
stream.writeByte('"')
encoder.elemEncoder.Encode(ptr, stream)
stream.writeByte('"')
}

func (encoder *stringModeNumberEncoder) IsEmpty(ptr unsafe.Pointer) bool {
func (encoder *stringModeNonStringEncoder) IsEmpty(ptr unsafe.Pointer) bool {
return encoder.elemEncoder.IsEmpty(ptr)
}

Expand Down
5 changes: 5 additions & 0 deletions type_tests/struct_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func init() {
F1 uint32 `json:"F1"`
F2 uint32 `json:"F2,string"`
})(nil),
(*struct {
F1 []int `json:"F1,string"`
F2 map[int]int `json:"F2,string"`
F3 bool `json:"F3,string"`
})(nil),
(*struct {
A string `json:"a,omitempty"`
B string `json:"b,omitempty"`
Expand Down