Skip to content

Commit

Permalink
fix bug vmihailenco#310
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonnix authored and Sonnix committed Sep 11, 2023
1 parent 75ea4db commit 44cff84
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions decode_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ func getDecoder(typ reflect.Type) decoderFunc {
}

func _getDecoder(typ reflect.Type) decoderFunc {
kind := typ.Kind()

if kind == reflect.Ptr {
if _, ok := typeDecMap.Load(typ.Elem()); ok {
return ptrValueDecoder(typ)
}
}

if typ.Implements(customDecoderType) {
return nilAwareDecoder(typ, decodeCustomValue)
}
Expand All @@ -77,6 +69,14 @@ func _getDecoder(typ reflect.Type) decoderFunc {
return nilAwareDecoder(typ, unmarshalTextValue)
}

kind := typ.Kind()

if kind == reflect.Ptr {
if _, ok := typeDecMap.Load(typ.Elem()); ok {
return ptrValueDecoder(typ)
}
}

// Addressable struct field value.
if kind != reflect.Ptr {
ptr := reflect.PtrTo(typ)
Expand Down Expand Up @@ -127,7 +127,7 @@ func ptrValueDecoder(typ reflect.Type) decoderFunc {
decoder := getDecoder(typ.Elem())
return func(d *Decoder, v reflect.Value) error {
if d.hasNilCode() {
if !v.IsNil() {
if !v.IsNil() && v.CanSet() {
v.Set(d.newValue(typ))
}
return d.DecodeNil()
Expand Down

0 comments on commit 44cff84

Please sign in to comment.