Skip to content

The output JSON should omit Field when Field.Valid is false #1

Open
@ggicci

Description

@ggicci

For example, when encoding the following struct instance to JSON:

type Example struct {
	Name patch.Field[string] `json:"name"`
	Age  patch.Field[int]    `json:"age"`
}

patch := &Example{
	Name: patch.Field[string]{Valid: false},
	Age:  patch.Field[int]{Valid: true, Value: 10},
}

Encode patch to JSON:

Got:

{"name": "", "age": 10}

Expect:

{"age": 10}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions