Skip to content

fix: exclude UnmarshalJSONFrom by default - #52

Merged
ldez merged 1 commit into
mainfrom
fix/exclude-unmarshal-json-from
Nov 5, 2026
Merged

ldez merged 1 commit into
mainfrom
fix/exclude-unmarshal-json-from

Conversation

@raeperd

@raeperd raeperd commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Why

encoding/json/v2 is stable in Go 1.27 (blog) and adds the UnmarshalerFrom interface:

UnmarshalJSONFrom(*jsontext.Decoder) error

Like UnmarshalJSON, it must use a pointer receiver. A value-receiver type that adopts it is reported today, while the same type with UnmarshalJSON is not:

type T struct{ N int }

func (t T) Get() int                                     { return t.N }
func (t *T) UnmarshalJSONFrom(d *jsontext.Decoder) error { ... }
// the methods of "T" use pointer receiver and non-pointer receiver.

What

  • Add *.UnmarshalJSONFrom to the built-in exclusions.
  • Add a JSONV2 type to the builtinmethods and disablebuiltin testdata. It uses local stand-ins for the jsontext types, so go.mod stays at go 1.26.0.
  • README: list the new exclusion and fix the config comment, which said MarshalJSON instead of UnmarshalJSON.

MarshalJSONTo is not excluded, the same as MarshalJSON.

Test

  • go test -race . passes, and golangci-lint run reports 0 issues.
  • With the analyzer.go change reverted, builtinmethods fails with an unexpected diagnostic on JSONV2.

encoding/json/v2 (stable in Go 1.27) adds the UnmarshalerFrom interface.
Like UnmarshalJSON, UnmarshalJSONFrom must use a pointer receiver, so
value-receiver types that adopt it were reported as mixed receivers.
@raeperd
raeperd added this pull request to stack #54 November 5, 2026 13:52
@raeperd
raeperd marked this pull request as ready for review November 5, 2026 13:54
@raeperd
raeperd requested a review from ldez November 5, 2026 13:54

@ldez ldez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ldez
ldez merged commit 91058d8 into main Nov 5, 2026
9 checks passed
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.

2 participants