You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The JSON marshalling of compact types like structs can be unique in some cases, which means we need to have unique encoder implementations. It would be nice to make the encoding/json/encode.go's newTypeEncoder function customisable. I mean this function accepts type information and based on that it will return an encoderFunc. Somehow if we are able to add custom implementations for different kinds that would make the json encoder more flexible.
High-level example of my thoughts:
// ------------ json package
const (
StructKind = "struct"
)
type customEncoder interface {
encode(e *encodeState, v reflect.Value, opts encOpts)
}
func SetEncoder(kind string, impl customEncoder) {
// TODO
}
// ------------ client impl
json.SetEncoder(json.StructKind, CustomStruct{})
type CustomStruct struct{}
func (CustomStruct) encode(e *encodeState, v reflect.Value, opts encOpts) {
// TODO
}
The text was updated successfully, but these errors were encountered:
Feature request
The JSON marshalling of compact types like structs can be unique in some cases, which means we need to have unique encoder implementations. It would be nice to make the encoding/json/encode.go's
newTypeEncoder
function customisable. I mean this function accepts type information and based on that it will return anencoderFunc
. Somehow if we are able to add custom implementations for different kinds that would make the json encoder more flexible.High-level example of my thoughts:
The text was updated successfully, but these errors were encountered: