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

Unmarshaling omits embedded pointer to an aliased primitive #372

Closed
ericklaus-wf opened this issue Jun 13, 2022 · 0 comments · Fixed by #378
Closed

Unmarshaling omits embedded pointer to an aliased primitive #372

ericklaus-wf opened this issue Jun 13, 2022 · 0 comments · Fixed by #378

Comments

@ericklaus-wf
Copy link

ericklaus-wf commented Jun 13, 2022

Related to #362

When unmarshaling a struct with an embedded pointer to an aliased primitive, the resulting struct omits the the pointer field leaving it nil.

The original struct is correctly serialized. For example, in the test below, the AliasedPrimitive field has a value of 7.

func TestIssue372(t *testing.T) {
	type AliasedPrimitive int
	type Combiner struct {
		SomeField int
		*AliasedPrimitive
	}
	aliasedPrimitive := AliasedPrimitive(7)
	originalCombiner := Combiner{AliasedPrimitive: &aliasedPrimitive}
	b, err := json.Marshal(originalCombiner)
	assertErr(t, err)
	newCombiner := Combiner{}
	err = json.Unmarshal(b, &newCombiner)
	assertErr(t, err)
	assertEq(t, "TestEmbeddedPrimitiveAlias", *originalCombiner.AliasedPrimitive, *newCombiner.AliasedPrimitive)
}

panics due to newCombiner.AliasedPrimitive being nil.

orisano added a commit to orisano/go-json that referenced this issue Jul 4, 2022
@goccy goccy closed this as completed in #378 Jul 5, 2022
goccy added a commit that referenced this issue Jul 5, 2022
Fix embedded primitive type encoding using alias
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