Skip to content

Unmarshaling omits embedded pointer to an aliased primitive #372

@ericklaus-wf

Description

@ericklaus-wf

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.

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