cloudwego / hertz

Go HTTP framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
5.28k stars 515 forks source link

[Bug] binding decoder always uses 'default' value when both 'default' and 'json' tags are present #1098

Closed jojoshuai closed 6 months ago

jojoshuai commented 6 months ago

Describe the bug

After upgrading the version from 0.6.2 to 0.7.2, I have encountered issues related to the handling of the 'default' tag within the BindAndValidate function. In particular, it seems that when both a 'default' and a 'json' tag are specified for a field, the decoder will always use the default value.

To Reproduce

Steps to reproduce the behavior:

  1. go get github.com/cloudwego/hertz@v0.6.2
  2. run code: with 'go run'
  3. call hertz server with curl -X POST 'http://127.0.0.1:8888/users' --header 'Content-Type: application/json;charset=UTF-8' -d '{"page_size": 11,"page": 2}'
  4. response body is {"page":2,"pageSize":11}
  5. go get github.com/cloudwego/hertz@v0.7.2
  6. repeat steps 2、3
  7. response body is {"page":1,"pageSize":10}
  8. if we remove "default" in go tag, there will be no issues.

Expected behavior

same output with 0.6.2

Hertz version:

0.7.2

Environment:

GOVERSION='go1.22.2'

FGYFFFF commented 6 months ago

https://github.com/cloudwego/hertz/pull/1056 has fix the problem. please go get @develop