feat: allow custom json encoder/decoder. #338
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The encoding/json package in the standard library isn't particularly performant, and there have been many first-party and third-party efforts to improve it. This patch allows users of the sdk to configure a custom json codec to marshall and unmarshall json with their tools of choice. Note: we can update to encoding/json/v2 as the default once it's marked stable in a future golang release.
For context, I started thinking about this because we wind up unmarshalling fairly large json payloads in the Oxide otel receiver. The resource/performance improvement from switching to a faster json library turned out to be small, but I thought I would check this in anyway—I'll take performance improvements even if small, and this may prove helpful for users making large volumes of requests through the sdk.