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

Wrong in UnmarshalJsonReader #4399

Open
wangshiben opened this issue Sep 28, 2024 · 2 comments
Open

Wrong in UnmarshalJsonReader #4399

wangshiben opened this issue Sep 28, 2024 · 2 comments

Comments

@wangshiben
Copy link

Describe the bug
I faced a minor problem when I used it. API's JSON response can't used in API's JSON request.It's improtent for some P2P communicate Server.

To Reproduce
Steps to reproduce the behavior, if applicable:

  1. The api code is

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

}

type response {}

service template {
@handler postDataTest
post /test (request) returns (response) // this API just simply fmt.Printf("receive :%s",request)

@handler getJsonData
get /get returns (request)

}


2. `/get` API returns Struct like this,or some other []byte like Hash256 result, pubKey....

```go
types.Request{
 	Bytes: []byte("11122344wsss"),
 	Name:  "test",
 }
  1. I visit /get and pass get result into /test

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

Expected behavior

Logic code in /test print "["11122344wsss","test"]" in console

Screenshots

Environments (please complete the following information):

  • OS: Windows10
  • go-zero version 1.2.1
  • goctl version 1.7.2

More description
I fixed it, and I alse make a pr. You can review it in the test file

@kevwan
Copy link
Contributor

kevwan commented Oct 2, 2024

Would you please give a demo code to reproduce this issue?

@wangshiben
Copy link
Author

wangshiben commented Oct 2, 2024

  1. make a main.api ,and code as follow
syntax = "v1"

info (
	title:   "type title here"
	desc:    "type desc here"
	author:  "type author here"
	email:   "type email here"
	version: "type version here"
)

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)
}
  1. run the bash like to make a go-zero file
goctl api go --api  main.api --dir ./ --style=goZero
  1. and code in the internal/logic/getJsonDataLogic.go ,add this
func (l *GetJsonDataLogic) GetJsonData() (resp *types.Request, err error) {
	return &types.Request{
		Bytes: []byte("11122344wsss"),
		Name:  "test",
	}, nil
}
  1. then visit /get,I got
    image
 {
        "bytes": "MTExMjIzNDR3c3Nz",
        "name": "test"
   }
  1. pass reslut to /test,like this:

image

then ,error happend

and you can run in https://github.com/zeromicro/go-zero/pull/4397/files (the test func)

by the way I also probably fix it ,and I also make a pr ( #4397)

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

No branches or pull requests

2 participants