Skip to content

JSON tag uses "omitempty" as the field name #33660

Closed
@Vasco-jofra

Description

@Vasco-jofra

Description

Hi! While doing a broad search for this pattern, I noticed that you use "omitempty" as the name of a structure field.

Args []any `json:"omitempty"`

Instead, I believe you intended to use ",omitempty" to keep the default name and add the omitempty option.

You can test this behavior with this simple Go program. As you can see by the result, the omitempty key in the JSON string gets unmarshaled to the field with the json:"omitempty" tag.

package main

import (
	"encoding/json"
	"fmt"
)

type SomeStruct struct {
	SomeField string `json:"omitempty"`
}

func main() {
	u := SomeStruct{}
	_ = json.Unmarshal([]byte(`{"omitempty": "123"}`), &u)
	fmt.Printf("Result: %#v\n", u)
	// Result: main.SomeStruct{SomeField:"123"}
}

Gitea Version

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

Database

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions