@@ -36,8 +36,8 @@ type checkIsEmpty interface {
3636type ctx struct {
3737 * frozenConfig
3838 prefix string
39- encoders map [reflect .Type ]ValEncoder
40- decoders map [reflect .Type ]ValDecoder
39+ encoders map [reflect2 .Type ]ValEncoder
40+ decoders map [reflect2 .Type ]ValDecoder
4141}
4242
4343func (b * ctx ) append (prefix string ) * ctx {
@@ -51,7 +51,7 @@ func (b *ctx) append(prefix string) *ctx {
5151
5252// ReadVal copy the underlying JSON into go interface, same as json.Unmarshal
5353func (iter * Iterator ) ReadVal (obj interface {}) {
54- typ := reflect .TypeOf (obj )
54+ typ := reflect2 .TypeOf (obj )
5555 if typ .Kind () != reflect .Ptr {
5656 iter .ReportError ("ReadVal" , "can only unmarshal into pointer" )
5757 return
@@ -71,29 +71,30 @@ func (stream *Stream) WriteVal(val interface{}) {
7171 stream .WriteNil ()
7272 return
7373 }
74- typ := reflect .TypeOf (val )
74+ typ := reflect2 .TypeOf (val )
7575 encoder := stream .cfg .EncoderOf (typ )
7676 encoder .Encode (reflect2 .PtrOf (val ), stream )
7777}
7878
79- func (cfg * frozenConfig ) DecoderOf (typ reflect .Type ) ValDecoder {
80- cacheKey := typ
79+ func (cfg * frozenConfig ) DecoderOf (typ reflect2 .Type ) ValDecoder {
80+ cacheKey := typ . RType ()
8181 decoder := cfg .getDecoderFromCache (cacheKey )
8282 if decoder != nil {
8383 return decoder
8484 }
8585 ctx := & ctx {
8686 frozenConfig : cfg ,
8787 prefix : "" ,
88- decoders : map [reflect .Type ]ValDecoder {},
89- encoders : map [reflect .Type ]ValEncoder {},
88+ decoders : map [reflect2 .Type ]ValDecoder {},
89+ encoders : map [reflect2 .Type ]ValEncoder {},
9090 }
91- decoder = decoderOfType (ctx , typ .Elem ())
91+ ptrType := typ .(* reflect2.UnsafePtrType )
92+ decoder = decoderOfType (ctx , ptrType .Elem ())
9293 cfg .addDecoderToCache (cacheKey , decoder )
9394 return decoder
9495}
9596
96- func decoderOfType (ctx * ctx , typ reflect .Type ) ValDecoder {
97+ func decoderOfType (ctx * ctx , typ reflect2 .Type ) ValDecoder {
9798 decoder := getTypeDecoderFromExtension (ctx , typ )
9899 if decoder != nil {
99100 return decoder
@@ -108,7 +109,7 @@ func decoderOfType(ctx *ctx, typ reflect.Type) ValDecoder {
108109 return decoder
109110}
110111
111- func createDecoderOfType (ctx * ctx , typ reflect .Type ) ValDecoder {
112+ func createDecoderOfType (ctx * ctx , typ reflect2 .Type ) ValDecoder {
112113 decoder := ctx .decoders [typ ]
113114 if decoder != nil {
114115 return decoder
@@ -120,7 +121,7 @@ func createDecoderOfType(ctx *ctx, typ reflect.Type) ValDecoder {
120121 return decoder
121122}
122123
123- func _createDecoderOfType (ctx * ctx , typ reflect .Type ) ValDecoder {
124+ func _createDecoderOfType (ctx * ctx , typ reflect2 .Type ) ValDecoder {
124125 decoder := createDecoderOfJsonRawMessage (ctx , typ )
125126 if decoder != nil {
126127 return decoder
@@ -143,8 +144,8 @@ func _createDecoderOfType(ctx *ctx, typ reflect.Type) ValDecoder {
143144 }
144145 switch typ .Kind () {
145146 case reflect .Interface :
146- if typ .NumMethod () > 0 {
147- ifaceType := reflect2 . Type2 ( typ ).( * reflect2. UnsafeIFaceType )
147+ ifaceType , isIFace := typ .( * reflect2. UnsafeIFaceType )
148+ if isIFace {
148149 return & ifaceDecoder {valType : ifaceType }
149150 }
150151 return & efaceDecoder {}
@@ -163,20 +164,20 @@ func _createDecoderOfType(ctx *ctx, typ reflect.Type) ValDecoder {
163164 }
164165}
165166
166- func (cfg * frozenConfig ) EncoderOf (typ reflect .Type ) ValEncoder {
167- cacheKey := typ
167+ func (cfg * frozenConfig ) EncoderOf (typ reflect2 .Type ) ValEncoder {
168+ cacheKey := typ . RType ()
168169 encoder := cfg .getEncoderFromCache (cacheKey )
169170 if encoder != nil {
170171 return encoder
171172 }
172173 ctx := & ctx {
173174 frozenConfig : cfg ,
174175 prefix : "" ,
175- decoders : map [reflect .Type ]ValDecoder {},
176- encoders : map [reflect .Type ]ValEncoder {},
176+ decoders : map [reflect2 .Type ]ValDecoder {},
177+ encoders : map [reflect2 .Type ]ValEncoder {},
177178 }
178179 encoder = encoderOfType (ctx , typ )
179- if shouldFixOnePtr ( typ ) {
180+ if typ . LikePtr ( ) {
180181 encoder = & onePtrEncoder {encoder }
181182 }
182183 cfg .addEncoderToCache (cacheKey , encoder )
@@ -195,11 +196,7 @@ func (encoder *onePtrEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
195196 encoder .encoder .Encode (unsafe .Pointer (& ptr ), stream )
196197}
197198
198- func shouldFixOnePtr (typ reflect.Type ) bool {
199- return reflect2 .Type2 (typ ).LikePtr ()
200- }
201-
202- func encoderOfType (ctx * ctx , typ reflect.Type ) ValEncoder {
199+ func encoderOfType (ctx * ctx , typ reflect2.Type ) ValEncoder {
203200 encoder := getTypeEncoderFromExtension (ctx , typ )
204201 if encoder != nil {
205202 return encoder
@@ -214,7 +211,7 @@ func encoderOfType(ctx *ctx, typ reflect.Type) ValEncoder {
214211 return encoder
215212}
216213
217- func createEncoderOfType (ctx * ctx , typ reflect .Type ) ValEncoder {
214+ func createEncoderOfType (ctx * ctx , typ reflect2 .Type ) ValEncoder {
218215 encoder := ctx .encoders [typ ]
219216 if encoder != nil {
220217 return encoder
@@ -225,7 +222,7 @@ func createEncoderOfType(ctx *ctx, typ reflect.Type) ValEncoder {
225222 placeholder .encoder = encoder
226223 return encoder
227224}
228- func _createEncoderOfType (ctx * ctx , typ reflect .Type ) ValEncoder {
225+ func _createEncoderOfType (ctx * ctx , typ reflect2 .Type ) ValEncoder {
229226 encoder := createEncoderOfJsonRawMessage (ctx , typ )
230227 if encoder != nil {
231228 return encoder
@@ -249,7 +246,7 @@ func _createEncoderOfType(ctx *ctx, typ reflect.Type) ValEncoder {
249246 kind := typ .Kind ()
250247 switch kind {
251248 case reflect .Interface :
252- return & dynamicEncoder {reflect2 . Type2 ( typ ) }
249+ return & dynamicEncoder {typ }
253250 case reflect .Struct :
254251 return encoderOfStruct (ctx , typ )
255252 case reflect .Array :
0 commit comments