Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to json.RawMessage attribute #189

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@ func unmarshalAttribute(
return
}

// Field was a json.RawMessage
if fieldValue.Type() == reflect.TypeOf(json.RawMessage{}) {
value, err = handleRawMessage(attribute)
}

// As a final catch-all, ensure types line up to avoid a runtime panic.
if fieldValue.Kind() != value.Kind() {
err = ErrInvalidType
Expand All @@ -434,6 +439,14 @@ func unmarshalAttribute(
return
}

func handleRawMessage(attribute interface{}) (reflect.Value, error) {
raw, err := json.Marshal(attribute)
if err != nil {
return reflect.Value{}, err
}
return reflect.ValueOf(raw), nil
}

func handleStringSlice(attribute interface{}) (reflect.Value, error) {
v := reflect.ValueOf(attribute)
values := make([]string, v.Len())
Expand Down