1package test 2 3import ( 4 "encoding" 5 "encoding/json" 6) 7 8func init() { 9 jm := json.Marshaler(jmOfStruct{}) 10 tm1 := encoding.TextMarshaler(tmOfStruct{}) 11 tm2 := encoding.TextMarshaler(&tmOfStructInt{}) 12 marshalCases = append(marshalCases, 13 jmOfStruct{}, 14 &jm, 15 tmOfStruct{}, 16 &tm1, 17 tmOfStructInt{}, 18 &tm2, 19 map[tmOfStruct]int{ 20 {}: 100, 21 }, 22 map[*tmOfStruct]int{ 23 {}: 100, 24 }, 25 map[encoding.TextMarshaler]int{ 26 tm1: 100, 27 }, 28 ) 29 unmarshalCases = append(unmarshalCases, unmarshalCase{ 30 ptr: (*tmOfMap)(nil), 31 input: `"{1:2}"`, 32 }, unmarshalCase{ 33 ptr: (*tmOfMapPtr)(nil), 34 input: `"{1:2}"`, 35 }) 36} 37 38type jmOfStruct struct { 39 F2 chan []byte 40} 41 42func (q jmOfStruct) MarshalJSON() ([]byte, error) { 43 return []byte(`""`), nil 44} 45 46func (q *jmOfStruct) UnmarshalJSON(value []byte) error { 47 return nil 48} 49 50type tmOfStruct struct { 51 F2 chan []byte 52} 53 54func (q tmOfStruct) MarshalText() ([]byte, error) { 55 return []byte(`""`), nil 56} 57 58func (q *tmOfStruct) UnmarshalText(value []byte) error { 59 return nil 60} 61 62type tmOfStructInt struct { 63 Field2 int 64} 65 66func (q *tmOfStructInt) MarshalText() ([]byte, error) { 67 return []byte(`"abc"`), nil 68} 69 70func (q *tmOfStructInt) UnmarshalText(value []byte) error { 71 return nil 72} 73 74type tmOfMap map[int]int 75 76func (q tmOfMap) UnmarshalText(value []byte) error { 77 return nil 78} 79 80type tmOfMapPtr map[int]int 81 82func (q *tmOfMapPtr) UnmarshalText(value []byte) error { 83 return nil 84} 85