mirror of
https://github.com/json-iterator/go.git
synced 2025-05-13 21:36:29 +02:00
#77 support -,
This commit is contained in:
parent
76e62088df
commit
82dabdcdbf
@ -231,7 +231,7 @@ func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, err
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tagParts := strings.Split(field.Tag.Get("json"), ",")
|
tagParts := strings.Split(field.Tag.Get("json"), ",")
|
||||||
fieldNames := calcFieldNames(field.Name, tagParts[0])
|
fieldNames := calcFieldNames(field.Name, tagParts[0], string(field.Tag))
|
||||||
fieldCacheKey := fmt.Sprintf("%s/%s", typ.String(), field.Name)
|
fieldCacheKey := fmt.Sprintf("%s/%s", typ.String(), field.Name)
|
||||||
decoder := fieldDecoders[fieldCacheKey]
|
decoder := fieldDecoders[fieldCacheKey]
|
||||||
if decoder == nil {
|
if decoder == nil {
|
||||||
@ -295,22 +295,22 @@ func describeStruct(cfg *frozenConfig, typ reflect.Type) (*StructDescriptor, err
|
|||||||
return structDescriptor, nil
|
return structDescriptor, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcFieldNames(originalFieldName string, tagProvidedFieldName string) []string {
|
func calcFieldNames(originalFieldName string, tagProvidedFieldName string, wholeTag string) []string {
|
||||||
// tag => exported? => original
|
// ignore?
|
||||||
isNotExported := unicode.IsLower(rune(originalFieldName[0]))
|
if wholeTag == "-" {
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
// rename?
|
||||||
var fieldNames []string
|
var fieldNames []string
|
||||||
/// tagParts[0] always present, even if no tags
|
if tagProvidedFieldName == "" {
|
||||||
switch tagProvidedFieldName {
|
fieldNames = []string{originalFieldName}
|
||||||
case "":
|
} else {
|
||||||
if isNotExported {
|
|
||||||
fieldNames = []string{}
|
|
||||||
} else {
|
|
||||||
fieldNames = []string{originalFieldName}
|
|
||||||
}
|
|
||||||
case "-":
|
|
||||||
fieldNames = []string{}
|
|
||||||
default:
|
|
||||||
fieldNames = []string{tagProvidedFieldName}
|
fieldNames = []string{tagProvidedFieldName}
|
||||||
}
|
}
|
||||||
|
// private?
|
||||||
|
isNotExported := unicode.IsLower(rune(originalFieldName[0]))
|
||||||
|
if isNotExported {
|
||||||
|
fieldNames = []string{}
|
||||||
|
}
|
||||||
return fieldNames
|
return fieldNames
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user