1
0
mirror of https://github.com/json-iterator/go.git synced 2025-08-07 21:52:55 +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

@ -71,19 +71,57 @@ func init() {
Map map[string]string
})(nil),
(*[]uint8)(nil),
(*[]GeoLocation)(nil),
(*[]jsonMarshaler)(nil),
(*[]jsonMarshalerMap)(nil),
(*[]textMarshaler)(nil),
(*[]textMarshalerMap)(nil),
)
}
type GeoLocation struct {
type jsonMarshaler struct {
Id string `json:"id,omitempty" db:"id"`
}
func (p *GeoLocation) MarshalJSON() ([]byte, error) {
func (p *jsonMarshaler) MarshalJSON() ([]byte, error) {
return []byte(`{}`), nil
}
func (p *GeoLocation) UnmarshalJSON(input []byte) error {
func (p *jsonMarshaler) UnmarshalJSON(input []byte) error {
p.Id = "hello"
return nil
}
type jsonMarshalerMap map[int]int
func (p *jsonMarshalerMap) MarshalJSON() ([]byte, error) {
return []byte(`{}`), nil
}
func (p *jsonMarshalerMap) UnmarshalJSON(input []byte) error {
return nil
}
type textMarshaler struct {
Id string `json:"id,omitempty" db:"id"`
}
func (p *textMarshaler) MarshalText() ([]byte, error) {
return []byte(`{}`), nil
}
func (p *textMarshaler) UnmarshalText(input []byte) error {
p.Id = "hello"
return nil
}
type textMarshalerMap map[int]int
func (p *textMarshalerMap) MarshalText() ([]byte, error) {
return []byte(`{}`), nil
}
func (p *textMarshalerMap) UnmarshalText(input []byte) error {
return nil
}