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 {
1818
1919func (extension * namingStrategyExtension ) UpdateStructDescriptor (structDescriptor * jsoniter.StructDescriptor ) {
2020for _ , binding := range structDescriptor .Fields {
21+ if unicode .IsLower (rune (binding .Field .Name ()[0 ])) {
22+ continue
23+ }
2124tag , hastag := binding .Field .Tag ().Lookup ("json" )
2225if hastag {
2326tagParts := 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) {
4848should .Nil (err )
4949should .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+ }
You can’t perform that action at this time.
0 commit comments