mirror of
https://github.com/retailcrm/api-client-go.git
synced 2024-11-22 04:46:03 +03:00
Fix incorrect marshaling for some string maps
This commit is contained in:
commit
e9b2a04a4a
@ -34,21 +34,21 @@ func (a *APIErrorsList) UnmarshalJSON(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *CustomFieldsList) UnmarshalJSON(data []byte) error {
|
||||
func (l *StringMap) UnmarshalJSON(data []byte) error {
|
||||
var i interface{}
|
||||
var m CustomFieldsList
|
||||
var m StringMap
|
||||
if err := json.Unmarshal(data, &i); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch e := i.(type) {
|
||||
case map[string]interface{}:
|
||||
m = make(CustomFieldsList, len(e))
|
||||
m = make(StringMap, len(e))
|
||||
for idx, val := range e {
|
||||
m[idx] = fmt.Sprint(val)
|
||||
}
|
||||
case []interface{}:
|
||||
m = make(CustomFieldsList, len(e))
|
||||
m = make(StringMap, len(e))
|
||||
for idx, val := range e {
|
||||
m[strconv.Itoa(idx)] = fmt.Sprint(val)
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func TestAPIErrorsList_UnmarshalJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCustomFieldsList_UnmarshalJSON(t *testing.T) {
|
||||
var list CustomFieldsList
|
||||
var list StringMap
|
||||
|
||||
require.NoError(t, json.Unmarshal([]byte(`["first", "second"]`), &list))
|
||||
assert.Len(t, list, 2)
|
||||
|
20
types.go
20
types.go
@ -155,7 +155,7 @@ type Customer struct {
|
||||
BrowserID string `json:"browserId,omitempty"`
|
||||
MgCustomerID string `json:"mgCustomerId,omitempty"`
|
||||
PhotoURL string `json:"photoUrl,omitempty"`
|
||||
CustomFields CustomFieldsList `json:"customFields,omitempty"`
|
||||
CustomFields StringMap `json:"customFields,omitempty"`
|
||||
Tags []Tag `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ type CorporateCustomer struct {
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
Vip bool `json:"vip,omitempty"`
|
||||
Bad bool `json:"bad,omitempty"`
|
||||
CustomFields CustomFieldsList `json:"customFields,omitempty"`
|
||||
CustomFields StringMap `json:"customFields,omitempty"`
|
||||
PersonalDiscount float32 `json:"personalDiscount,omitempty"`
|
||||
DiscountCardNumber string `json:"discountCardNumber,omitempty"`
|
||||
ManagerID int `json:"managerId,omitempty"`
|
||||
@ -228,7 +228,7 @@ type Company struct {
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
Contragent *Contragent `json:"contragent,omitempty"`
|
||||
Address *IdentifiersPair `json:"address,omitempty"`
|
||||
CustomFields CustomFieldsList `json:"customFields,omitempty"`
|
||||
CustomFields StringMap `json:"customFields,omitempty"`
|
||||
}
|
||||
|
||||
// CorporateCustomerNote type.
|
||||
@ -274,7 +274,7 @@ Order related types
|
||||
*/
|
||||
|
||||
type OrderPayments map[string]OrderPayment
|
||||
type CustomFieldsList map[string]string
|
||||
type StringMap map[string]string
|
||||
|
||||
// Order type.
|
||||
type Order struct {
|
||||
@ -325,7 +325,7 @@ type Order struct {
|
||||
Delivery *OrderDelivery `json:"delivery,omitempty"`
|
||||
Marketplace *OrderMarketplace `json:"marketplace,omitempty"`
|
||||
Items []OrderItem `json:"items,omitempty"`
|
||||
CustomFields CustomFieldsList `json:"customFields,omitempty"`
|
||||
CustomFields StringMap `json:"customFields,omitempty"`
|
||||
Payments OrderPayments `json:"payments,omitempty"`
|
||||
}
|
||||
|
||||
@ -522,7 +522,7 @@ type Offer struct {
|
||||
Length float32 `json:"length,omitempty"`
|
||||
Weight float32 `json:"weight,omitempty"`
|
||||
Stores []Inventory `json:"stores,omitempty"`
|
||||
Properties map[string]string `json:"properties,omitempty"`
|
||||
Properties StringMap `json:"properties,omitempty"`
|
||||
Prices []OfferPrice `json:"prices,omitempty"`
|
||||
Images []string `json:"images,omitempty"`
|
||||
Unit *Unit `json:"unit,omitempty"`
|
||||
@ -931,7 +931,7 @@ type Product struct {
|
||||
Quantity float32 `json:"quantity,omitempty"`
|
||||
Offers []Offer `json:"offers,omitempty"`
|
||||
Groups []ProductGroup `json:"groups,omitempty"`
|
||||
Properties map[string]string `json:"properties,omitempty"`
|
||||
Properties StringMap `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
// DeliveryHistoryRecord type.
|
||||
@ -955,7 +955,7 @@ type DeliveryShipment struct {
|
||||
LunchTime string `json:"lunchTime,omitempty"`
|
||||
Comment string `json:"comment,omitempty"`
|
||||
Orders []Order `json:"orders,omitempty"`
|
||||
ExtraData map[string]string `json:"extraData,omitempty"`
|
||||
ExtraData StringMap `json:"extraData,omitempty"`
|
||||
}
|
||||
|
||||
// IntegrationModule type.
|
||||
@ -971,7 +971,7 @@ type IntegrationModule struct {
|
||||
BaseURL string `json:"baseUrl,omitempty"`
|
||||
AccountURL string `json:"accountUrl,omitempty"`
|
||||
AvailableCountries []string `json:"availableCountries,omitempty"`
|
||||
Actions map[string]string `json:"actions,omitempty"`
|
||||
Actions StringMap `json:"actions,omitempty"`
|
||||
Integrations *Integrations `json:"integrations,omitempty"`
|
||||
}
|
||||
|
||||
@ -987,7 +987,7 @@ type Integrations struct {
|
||||
// Delivery type.
|
||||
type Delivery struct {
|
||||
Description string `json:"description,omitempty"`
|
||||
Actions map[string]string `json:"actions,omitempty"`
|
||||
Actions StringMap `json:"actions,omitempty"`
|
||||
PayerType []string `json:"payerType,omitempty"`
|
||||
PlatePrintLimit int `json:"platePrintLimit,omitempty"`
|
||||
RateDeliveryCost bool `json:"rateDeliveryCost,omitempty"`
|
||||
|
Loading…
Reference in New Issue
Block a user