Skip to content

Commit

Permalink
Alerts can be object or array
Browse files Browse the repository at this point in the history
  • Loading branch information
Fank committed Apr 24, 2023
1 parent fd6856f commit f0bb16c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions shipment_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,38 @@ type Response struct {
// TransactionReference *TransactionReference // buggy
}

func (s *Response) UnmarshalJSON(data []byte) error {
var v map[string]json.RawMessage
if err := json.Unmarshal(data, &v); err != nil {
return err
}

if status, ok := v["ResponseStatus"]; ok {
err := json.Unmarshal(status, &s.ResponseStatus)
if err != nil {
return err
}
}

if alert, ok := v["Alert"]; ok {
if alert[0] == '{' {
s.Alerts = make([]Alert, 1)

err := json.Unmarshal(alert, &s.Alerts[0])
if err != nil {
return err
}
} else {
err := json.Unmarshal(alert, &s.Alerts)
if err != nil {
return err
}
}
}

return nil
}

type ResponseStatus struct {
// Identifies the success or failure of the transaction. 1 = Successful
Code string
Expand Down

0 comments on commit f0bb16c

Please sign in to comment.