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

fix: wrong way of Unmarshal #4397

Merged
merged 1 commit into from
Jan 22, 2025
Merged

fix: wrong way of Unmarshal #4397

merged 1 commit into from
Jan 22, 2025

Conversation

wangshiben
Copy link
Contributor

I faced a minor problem when I used it.
for examlpe:

type request {
	Bytes []byte `json:"bytes"`
	Name  string `json:"name"`
}

type response {}

service template {
	@handler postDataTest
	post /test (request) returns (response)

	@handler getJsonData
	get /get returns (request)
}

and get returns

&types.Request{
		Bytes: []byte("11122344wsss"),
		Name:  "test",
	}

It's ok when I visit /get api ,but when I put /get response (the json data of request) into /test error happend:

fullName: `bytes`, error: `string: `MTExMjIzNDR3c3Nz`, error: `invalid character 'M' looking for beginning of value``

and I notice that ,there use json.Marshal() to make the response but use slef custom mapping.UnmarshalJsonReader to Unmarshal json data

so I just fix it (core in mapping.processFieldNotFromString).

You can see test in TestUnmarshalJsonReaderMultiArray

@wangshiben
Copy link
Contributor Author

@kevwan please help review

Copy link

codecov bot commented Jan 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.56%. Comparing base (8690859) to head (c7683bf).
Report is 226 commits behind head on master.

Additional details and impacted files
Files with missing lines Coverage Δ
core/mapping/unmarshaler.go 96.28% <100.00%> (-0.20%) ⬇️

... and 7 files with indirect coverage changes

…onx.Marshal but jsonx.Umarshal works wrong way
@kevwan kevwan added this pull request to the merge queue Jan 22, 2025
Merged via the queue into zeromicro:master with commit 238c92a Jan 22, 2025
6 checks passed
@kevwan kevwan linked an issue Jan 22, 2025 that may be closed by this pull request
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 this pull request may close these issues.

Bug: httpx.ParseJsonBody don't support bytes field
2 participants