Skip to content

Commit 93a1527

Browse files
committed
chore: incorporate review feedback
1 parent 3414f84 commit 93a1527

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

nullable.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@ package jsonapi
22

33
import (
44
"errors"
5-
"reflect"
65
"time"
76
)
87

9-
var SupportedNullableTypes = map[string]reflect.Value{
10-
"bool": reflect.ValueOf(false),
11-
"time.Time": reflect.ValueOf(time.Time{}),
12-
}
13-
148
// Nullable is a generic type, which implements a field that can be one of three states:
159
//
1610
// - field is not set in the request

request.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"io"
99
"reflect"
10-
"regexp"
1110
"strconv"
1211
"strings"
1312
"time"
@@ -675,10 +674,10 @@ func handleNullable(
675674
}
676675
}
677676

678-
var rgx = regexp.MustCompile(`\[(.*)\]`)
679-
rs := rgx.FindStringSubmatch(fieldValue.Type().Name())
677+
innerType := fieldValue.Type().Elem()
678+
zeroValue := reflect.Zero(innerType)
680679

681-
attrVal, err := unmarshalAttribute(attribute, args, structField, SupportedNullableTypes[rs[1]])
680+
attrVal, err := unmarshalAttribute(attribute, args, structField, zeroValue)
682681
if err != nil {
683682
return reflect.ValueOf(nil), err
684683
}

0 commit comments

Comments
 (0)