Skip to content

[Bug] Incorrect JSON serialization tag #1162

Open
@Vasco-jofra

Description

@Vasco-jofra

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"}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions