Skip to content
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

OnlyTaggedField should not skip embedded structs #308

Closed
masterada opened this issue Sep 14, 2018 · 0 comments
Closed

OnlyTaggedField should not skip embedded structs #308

masterada opened this issue Sep 14, 2018 · 0 comments

Comments

@masterada
Copy link
Contributor

Given the following test:

	type Embedded struct {
		EField string `json:"e_field"`
	}

	type myStruct struct {
		Field string `json:"field"`
		Embedded
	}

	m := myStruct{
		Field: "field",
		Embedded: Embedded{
			EField: "e_field",
		},
	}

	b, _ := jsoniter.Config{OnlyTaggedField: true}.Froze().Marshal(m)
	fmt.Print(string(b))

Expected: {"field":"field","e_field":"e_field"}
Got: {"field":"field"}

Workaround:
If I add json:"" tag to embedded, it works:

	type Embedded struct {
		EField string `json:"e_field"`
	}

	type myStruct struct {
		Field string `json:"field"`
		Embedded `json:""`
	}

	m := myStruct{
		Field: "field",
		Embedded: Embedded{
			EField: "e_field",
		},
	}

	b, _ := jsoniter.Config{OnlyTaggedField: true}.Froze().Marshal(m)
	fmt.Print(string(b))
masterada added a commit to proemergotech/go that referenced this issue Oct 29, 2018
taowen added a commit that referenced this issue Feb 8, 2019
fix #308 do NOT skip embedded structs without tag when OnlyTaggedFiel…
zhenzou pushed a commit to zhenzou/jsoniter that referenced this issue Feb 2, 2022
zhenzou pushed a commit to zhenzou/jsoniter that referenced this issue Feb 2, 2022
fix json-iterator#308 do NOT skip embedded structs without tag when OnlyTaggedFiel…
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

No branches or pull requests

1 participant