mirror of
https://github.com/json-iterator/go.git
synced 2024-11-24 08:22:14 +02:00
25 lines
572 B
Go
25 lines
572 B
Go
package extra
|
|
|
|
import (
|
|
"github.com/json-iterator/go"
|
|
"unicode"
|
|
)
|
|
|
|
func SupportPrivateFields() {
|
|
jsoniter.RegisterExtension(&privateFieldsExtension{})
|
|
}
|
|
|
|
type privateFieldsExtension struct {
|
|
jsoniter.DummyExtension
|
|
}
|
|
|
|
func (extension *privateFieldsExtension) UpdateStructDescriptor(structDescriptor *jsoniter.StructDescriptor) {
|
|
for _, binding := range structDescriptor.Fields {
|
|
isPrivate := unicode.IsLower(rune(binding.Field.Name[0]))
|
|
if isPrivate {
|
|
binding.FromNames = []string{binding.Field.Name}
|
|
binding.ToNames = []string{binding.Field.Name}
|
|
}
|
|
}
|
|
}
|