github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/msgfmt/jsonfmt/level_1/struct_test.go (about) 1 package test 2 3 import ( 4 "testing" 5 "github.com/stretchr/testify/require" 6 "github.com/v2pro/plz/msgfmt/jsonfmt" 7 "github.com/v2pro/plz/reflect2" 8 ) 9 10 func Test_struct(t *testing.T) { 11 should := require.New(t) 12 type TestObject struct { 13 Field1 string 14 Field2 int `json:"field_2"` 15 } 16 encoder := jsonfmt.EncoderOf(reflect2.TypeOf(TestObject{})) 17 output := encoder.Encode(nil,nil, reflect2.PtrOf(TestObject{"hello", 100})) 18 should.Equal(`{"Field1":"hello","field_2":100}`, string(output)) 19 }