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

Panic When Umarshal []struct Data from String #4491

Closed
chowyu12 opened this issue Dec 12, 2024 · 1 comment · Fixed by #4498
Closed

Panic When Umarshal []struct Data from String #4491

chowyu12 opened this issue Dec 12, 2024 · 1 comment · Fixed by #4498

Comments

@chowyu12
Copy link
Contributor

chowyu12 commented Dec 12, 2024

function path:

fillSliceFromString
fillSliceValue

https://github.com/zeromicro/go-zero/blob/master/core/mapping/unmarshaler.go#L266

api Define

type GoodsInfo {
	Sku             int64  `json:"sku,optional"`  
}

type GetReq {
	GoodsList    []*PromotionGoodsInfo `json:"goods_list"`
}

request Body

{
    "goods_list": "[{\"sku\":1003001442820970},{\"sku\":1003001442626969},{\"sku\":1003001442310851},{\"sku\":1003001445182314},{\"sku\":100300104903791},{\"sku\":1003001442626966},{\"sku\":1003001441414899},{\"sku\":1003001445184038},{\"sku\":1003001442658793},{\"sku\":1003001443446765}]\\",
}

return panic

ERRO[2024-12-12T10:57:22+08:00] panic: reflect: Key of non-map type types.GoodsInfo
@kevwan kevwan linked a pull request Dec 15, 2024 that will close this issue
@kevwan
Copy link
Contributor

kevwan commented Dec 20, 2024

{
    "goods_list": "[{\"sku\":1003001442820970},{\"sku\":1003001442626969},{\"sku\":1003001442310851},{\"sku\":1003001445182314},{\"sku\":100300104903791},{\"sku\":1003001442626966},{\"sku\":1003001441414899},{\"sku\":1003001445184038},{\"sku\":1003001442658793},{\"sku\":1003001443446765}]\\",
}

The value of goods_list is a string, not an array.

As you defined, the json should be looked as below:

{
    "goods_list": [{"sku":1003001442820970},{"sku":1003001442626969}]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants