Skip to content

go 1.27 json/v2 for requests v2 - #146

Closed
edandavi wants to merge 2 commits into
gophertools:v2from
edandavi:v2
Closed

edandavi wants to merge 2 commits into
gophertools:v2from
edandavi:v2

Conversation

@edandavi

Copy link
Copy Markdown

No description provided.

edandavi and others added 2 commits November 10, 2026 18:21
JSONSerializer, JSONDeserializer and reqtest.ReplayJSON now use
encoding/json/v2. Update examples for v2's case-sensitive field
matching and omitempty semantics.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Package functions and Builder methods that use encoding/json (v1)
for backward compatibility with pre-v2 JSON behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@edandavi

Copy link
Copy Markdown
Author

Notes:

json/v2 has changed the interfaces of Serialize and Deserialize:

func Marshal(in any, opts ...Options) (out []byte, err error)
func Unmarshal(in []byte, out any, opts ...Options) (err error)

Should we update our interfaces accordingly (with json.Options)?

Alternatively, ToJson and FromBody could use json/v2 directly, without the Serialize interfaces. This would allow us to use UnmarshalRead, avoiding an extra buffer allocation when reading the response body, as shown below:

func ToJson(v any, opts ...json.Options) requests.ResponseHandler {
	return func(res *http.Response) error {
		return json.UnmarshalRead(res.Body, v, opts...)
	}
}

Please let me know what you think
Thank you.

@earthboundkid

Copy link
Copy Markdown
Collaborator

I have some uncommitted changes with this on my computer as well. Will push it when I get the chance. I think the de/serializer interface can stay the same, and just wrap jsonv2.

@earthboundkid

Copy link
Copy Markdown
Collaborator

See c6db4ba

@edandavi edandavi closed this Nov 11, 2026
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