Skip to content

Commit 2b9d50a

Browse files
authored
Merge pull request json-iterator#429 from AllenX2018/fix-typo
fix issue json-iterator#326
2 parents 3c391b4 + 8cfbddd commit 2b9d50a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

extra/naming_strategy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ type namingStrategyExtension struct {
1818

1919
func (extension *namingStrategyExtension) UpdateStructDescriptor(structDescriptor *jsoniter.StructDescriptor) {
2020
for _, binding := range structDescriptor.Fields {
21+
if unicode.IsLower(rune(binding.Field.Name()[0])) {
22+
continue
23+
}
2124
tag, hastag := binding.Field.Tag().Lookup("json")
2225
if hastag {
2326
tagParts := strings.Split(tag, ",")

extra/naming_strategy_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,17 @@ func Test_set_naming_strategy_with_omitempty(t *testing.T) {
4848
should.Nil(err)
4949
should.Equal(`{"user_name":"taowen"}`, string(output))
5050
}
51+
52+
func Test_set_naming_strategy_with_private_field(t *testing.T) {
53+
should := require.New(t)
54+
SetNamingStrategy(LowerCaseWithUnderscores)
55+
output, err := jsoniter.Marshal(struct {
56+
UserName string
57+
userId int
58+
}{
59+
UserName: "allen",
60+
userId: 100,
61+
})
62+
should.Nil(err)
63+
should.Equal(`{"user_name":"allen"}`, string(output))
64+
}

0 commit comments

Comments
 (0)