I'm trying to change encoding in json, and used both encoding/json and jsoniter. What I'm trying to accomplish is that if I supply a language, it will encode relevant field names as "name@lang" instead of "name". I've ben trying the following:
func registerFieldEncoder(field string) {
encoderFunc := func(p unsafe.Pointer, stream *jsoniter.Stream) {
fmt.Print("test")
str := *(*string)(unsafe.Pointer(p))
newstr := str + "@sv"
stream.WriteString(newstr)
}
isEmptyFunc := func(p unsafe.Pointer) bool {
str := *(*string)(unsafe.Pointer(p))
return len(str) == 0
}
jsoniter.RegisterTypeEncoderFunc(field, encoderFunc, isEmptyFunc)
jsoniter.RegisterFieldEncoderFunc("", field, encoderFunc, isEmptyFunc) }
The field represents the json tag, i.e.
`json:"field`
Is this possible to accomplish in go?