You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-15 22:50:24 +02:00
support TextMarshaler as map key
This commit is contained in:
@ -8,11 +8,23 @@ import (
|
||||
func init() {
|
||||
jsonMarshaler := json.Marshaler(fakeJsonMarshaler{})
|
||||
textMarshaler := encoding.TextMarshaler(fakeTextMarshaler{})
|
||||
textMarshaler2 := encoding.TextMarshaler(&fakeTextMarshaler2{})
|
||||
marshalCases = append(marshalCases,
|
||||
fakeJsonMarshaler{},
|
||||
&jsonMarshaler,
|
||||
fakeTextMarshaler{},
|
||||
&textMarshaler,
|
||||
fakeTextMarshaler2{},
|
||||
&textMarshaler2,
|
||||
map[fakeTextMarshaler]int{
|
||||
fakeTextMarshaler{}: 100,
|
||||
},
|
||||
map[*fakeTextMarshaler]int{
|
||||
&fakeTextMarshaler{}: 100,
|
||||
},
|
||||
map[encoding.TextMarshaler]int{
|
||||
textMarshaler: 100,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@ -40,3 +52,15 @@ func (q fakeTextMarshaler) MarshalText() ([]byte, error) {
|
||||
func (q *fakeTextMarshaler) UnmarshalText(value []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type fakeTextMarshaler2 struct {
|
||||
Field2 int
|
||||
}
|
||||
|
||||
func (q *fakeTextMarshaler2) MarshalText() ([]byte, error) {
|
||||
return []byte(`"abc"`), nil
|
||||
}
|
||||
|
||||
func (q *fakeTextMarshaler2) UnmarshalText(value []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user