Skip to content

Conversation

@C-Pro
Copy link

@C-Pro C-Pro commented Mar 14, 2025

When attempting to marshal a field containing a nil value of a type implementing one of the Marshaller interfaces, generated code panics when attempting to call corresponding Marshal function on non-nil interface containing nil value.

Given these type definitions:

// easyjson:json
type WrapperType struct {
	Inner any `json:"Inner"`
}

// easyjson:json
type InterfaceType struct {
	Field1 int `json:"Field1"`
}

This code will cause a panic:

	var inner *InterfaceType
	wrapper := WrapperType{
		Inner: inner,
	}

	data, err := wrapper.MarshalJSON() // This will panic

In this PR I add extra check for nil interface value in the generated code and a test that fails before the fix and passes after.

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 this pull request may close these issues.

1 participant