1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00

fix marshaler support for iface case

This commit is contained in:
Tao Wen
2018-02-18 21:05:42 +08:00
parent 2074f25bd3
commit 43d9384d67
6 changed files with 246 additions and 91 deletions

View File

@ -1,19 +1,42 @@
package test
import (
"encoding/json"
"encoding"
)
func init() {
jsonMarshaler := json.Marshaler(fakeJsonMarshaler{})
textMarshaler := encoding.TextMarshaler(fakeTextMarshaler{})
marshalCases = append(marshalCases,
withChan{},
fakeJsonMarshaler{},
&jsonMarshaler,
fakeTextMarshaler{},
&textMarshaler,
)
}
type withChan struct {
type fakeJsonMarshaler struct {
F2 chan []byte
}
func (q withChan) MarshalJSON() ([]byte, error) {
func (q fakeJsonMarshaler) MarshalJSON() ([]byte, error) {
return []byte(`""`), nil
}
func (q *withChan) UnmarshalJSON(value []byte) error {
func (q *fakeJsonMarshaler) UnmarshalJSON(value []byte) error {
return nil
}
type fakeTextMarshaler struct {
F2 chan []byte
}
func (q fakeTextMarshaler) MarshalText() ([]byte, error) {
return []byte(`""`), nil
}
func (q *fakeTextMarshaler) UnmarshalText(value []byte) error {
return nil
}