fix: tolerate numeric recharge timestamps
This commit is contained in:
parent
157307a474
commit
ba8ed01b99
@ -211,8 +211,8 @@ type UserTotalRecharge struct {
|
|||||||
UserID Int64Value `json:"userId"`
|
UserID Int64Value `json:"userId"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Amount DecimalString `json:"amount"`
|
Amount DecimalString `json:"amount"`
|
||||||
CreateTime string `json:"createTime"`
|
CreateTime StringValue `json:"createTime"`
|
||||||
UpdateTime string `json:"updateTime"`
|
UpdateTime StringValue `json:"updateTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FreightSellerPage struct {
|
type FreightSellerPage struct {
|
||||||
@ -343,6 +343,26 @@ func (v *DecimalString) UnmarshalJSON(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StringValue string
|
||||||
|
|
||||||
|
func (v *StringValue) UnmarshalJSON(data []byte) error {
|
||||||
|
raw := strings.TrimSpace(string(data))
|
||||||
|
if raw == "" || raw == "null" {
|
||||||
|
*v = ""
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(raw, "\"") && strings.HasSuffix(raw, "\"") {
|
||||||
|
var parsed string
|
||||||
|
if err := json.Unmarshal(data, &parsed); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*v = StringValue(parsed)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
*v = StringValue(raw)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func New(cfg config.Config) *Client {
|
func New(cfg config.Config) *Client {
|
||||||
return &Client{
|
return &Client{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
|
|||||||
31
internal/integration/java_test.go
Normal file
31
internal/integration/java_test.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package integration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUserTotalRechargeAcceptsNumericTimestamps(t *testing.T) {
|
||||||
|
var item UserTotalRecharge
|
||||||
|
raw := []byte(`{
|
||||||
|
"id":"2049097310624870401",
|
||||||
|
"userId":"2042274349343506434",
|
||||||
|
"type":"SHIPPING_AGENT",
|
||||||
|
"amount":1.60,
|
||||||
|
"createTime":1777377844000,
|
||||||
|
"updateTime":1777556451000
|
||||||
|
}`)
|
||||||
|
|
||||||
|
if err := json.Unmarshal(raw, &item); err != nil {
|
||||||
|
t.Fatalf("json.Unmarshal() error = %v", err)
|
||||||
|
}
|
||||||
|
if item.CreateTime != "1777377844000" {
|
||||||
|
t.Fatalf("CreateTime = %q, want numeric timestamp string", item.CreateTime)
|
||||||
|
}
|
||||||
|
if item.UpdateTime != "1777556451000" {
|
||||||
|
t.Fatalf("UpdateTime = %q, want numeric timestamp string", item.UpdateTime)
|
||||||
|
}
|
||||||
|
if item.Amount != "1.60" {
|
||||||
|
t.Fatalf("Amount = %q, want 1.60", item.Amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user