You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From the Selling Partner api, finances api returns Date format of type ISO 8601, but type.gen.go files do not handle it correctly, causing processes such as Parse function (ParseListFinancialEventsResp, ParseListFinancialEventsByOrderIdResp etc.) to fail:
Error: json: cannot unmarshal string into Go struct field ShipmentEvent.payload.FinancialEvents.ShipmentEventList.PostedDate of type finances.Date
In order to fix that, we should define Date as struct, and implement an unmarshalJson for Date:
// Date defines model for Date.typeDatestruct {
time.Time
}
// UnmarshalJSON implements the json.Unmarshaler interface for Datefunc (d*Date) UnmarshalJSON(data []byte) error {
// Remove quotess:=strings.Trim(string(data), "\"")
// Parse the time using the correct layoutt, err:=time.Parse(time.RFC3339, s)
iferr!=nil {
layouts:= []string{
"2006-01-02T15:04:05Z07:00",
"2006-01-02T15:04:05Z",
"2006-01-02T15:04:05",
"2006-01-02",
}
for_, layout:=rangelayouts {
ift, err=time.Parse(layout, s); err==nil {
break
}
}
iferr!=nil {
returnerr
}
}
d.Time=treturnnil
}
I noticed this issue when trying to implement a new call for the finances api, but this could also happen on other apis
The text was updated successfully, but these errors were encountered:
From the Selling Partner api, finances api returns Date format of type ISO 8601, but
type.gen.go
files do not handle it correctly, causing processes such as Parse function (ParseListFinancialEventsResp
,ParseListFinancialEventsByOrderIdResp
etc.) to fail:In order to fix that, we should define Date as struct, and implement an unmarshalJson for Date:
I noticed this issue when trying to implement a new call for the finances api, but this could also happen on other apis
The text was updated successfully, but these errors were encountered: