Skip to content

Panic when marshaling embedded aliased primitive #362

@ericklaus-wf

Description

@ericklaus-wf

When marshaling a struct that has any field and also embeds an aliased primitive, go-json panics. Additionally, if the panic is resolved, the produced bytes are correct, but go-json ignores the aliased primitive when unmarshaling.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions