Skip to content

Commit 879813a

Browse files
committed
fix unmarshal bug with custom field name
the correct field was not found because of a wrong name check. Now it's always compared with lowercased names.
1 parent 52631ee commit 879813a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

api_interfaces_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ var _ = Describe("Test interface api type casting", func() {
105105
Expect(rec.Code).To(Equal(http.StatusOK))
106106
})
107107

108-
It("reproduce issue with lowercase renaming", func() {
109-
reqBody := strings.NewReader(`{"data": [{"attributes":{"customerId": 2 }, "type": "someDatas"}]}`)
108+
It("Post works with lowercase renaming", func() {
109+
reqBody := strings.NewReader(`{"data": [{"attributes":{"customerId": "2" }, "type": "someDatas"}]}`)
110110
req, err := http.NewRequest("POST", "/v1/someDatas", reqBody)
111111
Expect(err).To(BeNil())
112112
api.Handler().ServeHTTP(rec, req)

jsonapi/unmarshal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func UnmarshalInto(input map[string]interface{}, targetStructType reflect.Type,
260260
for x := 0; x < val.NumField(); x++ {
261261
tfield := val.Type().Field(x)
262262
name := GetTagValueByName(tfield, "name")
263-
if name == strings.ToLower(fieldName) {
263+
if strings.ToLower(name) == strings.ToLower(fieldName) {
264264
field = val.Field(x)
265265
}
266266
}

0 commit comments

Comments
 (0)