json-iterator / go

A high-performance 100% compatible drop-in replacement of "encoding/json"
http://jsoniter.com/migrate-from-go-std.html
MIT License
13.42k stars 1.03k forks source link

fix frozeWithCacheReuse #639

Open molon opened 2 years ago

molon commented 2 years ago
func Test_customize_map_key_encoder(t *testing.T) {
    should := require.New(t)
    cfg := jsoniter.Config{}.Froze()
    cfg.RegisterExtension(&testMapKeyExtension{})
    m := map[int]int{1: 2}

    b, err := cfg.MarshalIndent(m, "", "  ")
    should.NoError(err)
    should.Equal(`{
  "2": 2
}`, string(b))

    cfg = jsoniter.Config{}.Froze() // without testMapKeyExtension
    b, err = cfg.MarshalIndent(m, "", "  ")
    should.NoError(err)
// !!!!! Before fix, it won't be equal here !!!!!!!
    should.Equal(`{
  "1": 2
}`, string(b))
}