|
|
@@ -21,3 +21,30 @@ func Test_lower_case_with_underscores(t *testing.T) {
|
|
|
should.Nil(err)
|
|
|
should.Equal(`{"user_name":"taowen","first_language":"Chinese"}`, string(output))
|
|
|
}
|
|
|
+
|
|
|
+func Test_set_naming_strategy_with_overrides(t *testing.T) {
|
|
|
+ should := require.New(t)
|
|
|
+ SetNamingStrategy(LowerCaseWithUnderscores)
|
|
|
+ output, err := jsoniter.Marshal(struct {
|
|
|
+ UserName string `json:"UserName"`
|
|
|
+ FirstLanguage string
|
|
|
+ }{
|
|
|
+ UserName: "taowen",
|
|
|
+ FirstLanguage: "Chinese",
|
|
|
+ })
|
|
|
+ should.Nil(err)
|
|
|
+ should.Equal(`{"UserName":"taowen","first_language":"Chinese"}`, string(output))
|
|
|
+}
|
|
|
+
|
|
|
+func Test_set_naming_strategy_with_omitempty(t *testing.T) {
|
|
|
+ should := require.New(t)
|
|
|
+ SetNamingStrategy(LowerCaseWithUnderscores)
|
|
|
+ output, err := jsoniter.Marshal(struct {
|
|
|
+ UserName string
|
|
|
+ FirstLanguage string `json:",omitempty"`
|
|
|
+ }{
|
|
|
+ UserName: "taowen",
|
|
|
+ })
|
|
|
+ should.Nil(err)
|
|
|
+ should.Equal(`{"user_name":"taowen"}`, string(output))
|
|
|
+}
|