mirror of https://github.com/goccy/go-json.git
fix custom marshal for map key
This commit is contained in:
parent
41ad89fe02
commit
705f51716b
|
@ -2605,3 +2605,18 @@ func TestIssue386(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
type customMapKey string
|
||||
|
||||
func (b customMapKey) MarshalJSON() ([]byte, error) {
|
||||
return []byte("[]"), nil
|
||||
}
|
||||
|
||||
func TestCustomMarshalForMapKey(t *testing.T) {
|
||||
m := map[customMapKey]string{customMapKey("skipcustom"): "test"}
|
||||
expected, err := stdjson.Marshal(m)
|
||||
assertErr(t, err)
|
||||
got, err := json.Marshal(m)
|
||||
assertErr(t, err)
|
||||
assertEq(t, "custom map key", string(expected), string(got))
|
||||
}
|
||||
|
|
|
@ -506,8 +506,6 @@ func (c *Compiler) listElemCode(typ *runtime.Type) (Code, error) {
|
|||
|
||||
func (c *Compiler) mapKeyCode(typ *runtime.Type) (Code, error) {
|
||||
switch {
|
||||
case c.implementsMarshalJSON(typ):
|
||||
return c.marshalJSONCode(typ)
|
||||
case c.implementsMarshalText(typ):
|
||||
return c.marshalTextCode(typ)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue