You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-24 23:16:47 +02:00
fix encoder/decoder cast issue
This commit is contained in:
@ -248,17 +248,6 @@ func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, err
|
||||
Decoder: decoder,
|
||||
Encoder: encoder,
|
||||
}
|
||||
shouldOmitEmpty := false
|
||||
for _, tagPart := range tagParts[1:] {
|
||||
if tagPart == "omitempty" {
|
||||
shouldOmitEmpty = true
|
||||
} else if tagPart == "string" {
|
||||
binding.Decoder = &stringModeDecoder{binding.Decoder}
|
||||
binding.Encoder = &stringModeEncoder{binding.Encoder}
|
||||
}
|
||||
}
|
||||
binding.Decoder = &structFieldDecoder{&field, binding.Decoder}
|
||||
binding.Encoder = &structFieldEncoder{&field, binding.Encoder, shouldOmitEmpty}
|
||||
bindings = append(bindings, binding)
|
||||
}
|
||||
}
|
||||
@ -269,6 +258,20 @@ func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, err
|
||||
for _, extension := range extensions {
|
||||
extension.UpdateStructDescriptor(structDescriptor)
|
||||
}
|
||||
for _, binding := range structDescriptor.Fields {
|
||||
shouldOmitEmpty := false
|
||||
tagParts := strings.Split(binding.Field.Tag.Get("json"), ",")
|
||||
for _, tagPart := range tagParts[1:] {
|
||||
if tagPart == "omitempty" {
|
||||
shouldOmitEmpty = true
|
||||
} else if tagPart == "string" {
|
||||
binding.Decoder = &stringModeDecoder{binding.Decoder}
|
||||
binding.Encoder = &stringModeEncoder{binding.Encoder}
|
||||
}
|
||||
}
|
||||
binding.Decoder = &structFieldDecoder{binding.Field, binding.Decoder}
|
||||
binding.Encoder = &structFieldEncoder{binding.Field, binding.Encoder, shouldOmitEmpty}
|
||||
}
|
||||
return structDescriptor, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user