Skip to content

[Bug] Incorrect JSON serialization tag #1162

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

Open
Vasco-jofra opened this issue Feb 19, 2025 · 0 comments · May be fixed by #1163
Open

[Bug] Incorrect JSON serialization tag #1162

Vasco-jofra opened this issue Feb 19, 2025 · 0 comments · May be fixed by #1163

Comments

@Vasco-jofra
Copy link

Hi! While doing a quick code search, I found that the code incorrectly exposes the MaxTokens field with the - key during JSON marshaling and unmarshaling. This is caused by the json:"-,omitempty" tag; by adding the , after the -, the - becomes the field key.

MaxTokens int `json:"-,omitempty"`

MaxTokens int `json:"-,omitempty"`

You can confirm this Go behavior with the following script:

package main

import (
	"encoding/json"
	"fmt"
)


func main() {
	type Test struct {
		MaxTokens string `json:"-,omitempty"`
	}
	u := Test{}
	_ = json.Unmarshal([]byte(`{"-": "asd"}`), &u)
	fmt.Printf("Result: %#v\n", u)
	// Result: main.Test{MaxTokens:"asd"}
}
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.

1 participant