File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change 99
1010// newTypeDecoder constructs an decoderFunc for a type.
1111func newTypeDecoder (dt , st reflect.Type ) decoderFunc {
12- if dt .Implements (unmarshalerType ) {
12+ if reflect .PtrTo (dt ).Implements (unmarshalerType ) ||
13+ dt .Implements (unmarshalerType ) {
1314 return unmarshalerDecoder
1415 }
1516
@@ -204,11 +205,9 @@ func newPtrDecoder(dt, st reflect.Type) decoderFunc {
204205}
205206
206207func unmarshalerDecoder (dv , sv reflect.Value ) {
207- if dv .Kind () != reflect .Ptr {
208- panic (& InvalidUnmarshalError {sv .Type ()})
209- }
210- if dv .IsNil () {
211- dv .Set (reflect .New (dv .Type ().Elem ()))
208+ // modeled off of https://golang.org/src/encoding/json/decode.go?#L325
209+ if dv .Kind () != reflect .Ptr && dv .Type ().Name () != "" && dv .CanAddr () {
210+ dv = dv .Addr ()
212211 }
213212
214213 u := dv .Interface ().(Unmarshaler )
You can’t perform that action at this time.
0 commit comments