File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,9 @@ type namingStrategyExtension struct {
18
18
19
19
func (extension * namingStrategyExtension ) UpdateStructDescriptor (structDescriptor * jsoniter.StructDescriptor ) {
20
20
for _ , binding := range structDescriptor .Fields {
21
+ if unicode .IsLower (rune (binding .Field .Name ()[0 ])) {
22
+ continue
23
+ }
21
24
tag , hastag := binding .Field .Tag ().Lookup ("json" )
22
25
if hastag {
23
26
tagParts := strings .Split (tag , "," )
Original file line number Diff line number Diff line change @@ -48,3 +48,17 @@ func Test_set_naming_strategy_with_omitempty(t *testing.T) {
48
48
should .Nil (err )
49
49
should .Equal (`{"user_name":"taowen"}` , string (output ))
50
50
}
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
+ }
You can’t perform that action at this time.
0 commit comments