@@ -49,6 +49,33 @@ func decoderOfMapKey(ctx *ctx, typ reflect2.Type) ValDecoder {
49
49
return decoder
50
50
}
51
51
}
52
+
53
+ ptrType := reflect2 .PtrTo (typ )
54
+ if ptrType .Implements (unmarshalerType ) {
55
+ return & referenceDecoder {
56
+ & unmarshalerDecoder {
57
+ valType : ptrType ,
58
+ },
59
+ }
60
+ }
61
+ if typ .Implements (unmarshalerType ) {
62
+ return & unmarshalerDecoder {
63
+ valType : typ ,
64
+ }
65
+ }
66
+ if ptrType .Implements (textUnmarshalerType ) {
67
+ return & referenceDecoder {
68
+ & textUnmarshalerDecoder {
69
+ valType : ptrType ,
70
+ },
71
+ }
72
+ }
73
+ if typ .Implements (textUnmarshalerType ) {
74
+ return & textUnmarshalerDecoder {
75
+ valType : typ ,
76
+ }
77
+ }
78
+
52
79
switch typ .Kind () {
53
80
case reflect .String :
54
81
return decoderOfType (ctx , reflect2 .DefaultTypeOfKind (reflect .String ))
@@ -63,31 +90,6 @@ func decoderOfMapKey(ctx *ctx, typ reflect2.Type) ValDecoder {
63
90
typ = reflect2 .DefaultTypeOfKind (typ .Kind ())
64
91
return & numericMapKeyDecoder {decoderOfType (ctx , typ )}
65
92
default :
66
- ptrType := reflect2 .PtrTo (typ )
67
- if ptrType .Implements (unmarshalerType ) {
68
- return & referenceDecoder {
69
- & unmarshalerDecoder {
70
- valType : ptrType ,
71
- },
72
- }
73
- }
74
- if typ .Implements (unmarshalerType ) {
75
- return & unmarshalerDecoder {
76
- valType : typ ,
77
- }
78
- }
79
- if ptrType .Implements (textUnmarshalerType ) {
80
- return & referenceDecoder {
81
- & textUnmarshalerDecoder {
82
- valType : ptrType ,
83
- },
84
- }
85
- }
86
- if typ .Implements (textUnmarshalerType ) {
87
- return & textUnmarshalerDecoder {
88
- valType : typ ,
89
- }
90
- }
91
93
return & lazyErrorDecoder {err : fmt .Errorf ("unsupported map key type: %v" , typ )}
92
94
}
93
95
}
@@ -103,6 +105,19 @@ func encoderOfMapKey(ctx *ctx, typ reflect2.Type) ValEncoder {
103
105
return encoder
104
106
}
105
107
}
108
+
109
+ if typ == textMarshalerType {
110
+ return & directTextMarshalerEncoder {
111
+ stringEncoder : ctx .EncoderOf (reflect2 .TypeOf ("" )),
112
+ }
113
+ }
114
+ if typ .Implements (textMarshalerType ) {
115
+ return & textMarshalerEncoder {
116
+ valType : typ ,
117
+ stringEncoder : ctx .EncoderOf (reflect2 .TypeOf ("" )),
118
+ }
119
+ }
120
+
106
121
switch typ .Kind () {
107
122
case reflect .String :
108
123
return encoderOfType (ctx , reflect2 .DefaultTypeOfKind (reflect .String ))
@@ -117,17 +132,6 @@ func encoderOfMapKey(ctx *ctx, typ reflect2.Type) ValEncoder {
117
132
typ = reflect2 .DefaultTypeOfKind (typ .Kind ())
118
133
return & numericMapKeyEncoder {encoderOfType (ctx , typ )}
119
134
default :
120
- if typ == textMarshalerType {
121
- return & directTextMarshalerEncoder {
122
- stringEncoder : ctx .EncoderOf (reflect2 .TypeOf ("" )),
123
- }
124
- }
125
- if typ .Implements (textMarshalerType ) {
126
- return & textMarshalerEncoder {
127
- valType : typ ,
128
- stringEncoder : ctx .EncoderOf (reflect2 .TypeOf ("" )),
129
- }
130
- }
131
135
if typ .Kind () == reflect .Interface {
132
136
return & dynamicMapKeyEncoder {ctx , typ }
133
137
}
0 commit comments