This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Description
This is a regression and was not observed until fdfe0b9 19 Sep, But some changes went after that caused this regression. Please check the sample program.
package main
import (
"encoding/json"
"fmt"
jsoniter "github.com/json-iterator/go"
)
func jsoniterMarshal(input Result) {
bb, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(&input)
if err != nil {
fmt.Printf("JSONITER Error %v \n", err)
return
}
fmt.Printf("JSONITER Res %s \n", bb)
}
func jsonMarshal(input Result) {
bb, err := json.Marshal(&input)
if err != nil {
fmt.Printf("JSON Error %v \n", err)
return
}
fmt.Printf("JSON Res %s \n", bb)
}
type ErrMap map[string]error
type Status struct {
Total int `json:"total"`
ErrMaps ErrMap `json:"errMaps,omitempty"`
}
type Request interface {
}
type Result struct {
Name string `json:"name"`
Reqs Request `json:"Reqs"`
ResultStatus Status `json:"resultStatus"`
}
func (iem ErrMap) MarshalJSON() ([]byte, error) {
tmp := make(map[string]string, len(iem))
for k, v := range iem {
tmp[k] = v.Error()
}
return json.Marshal(tmp)
}
func main() {
eMap := make(ErrMap, 2)
eMap["first"] = fmt.Errorf("First Error")
eMap["second"] = fmt.Errorf("Second Error")
s := Status{Total: 100,
ErrMaps: eMap}
res := Result{ Name : "testing", ResultStatus: s, Reqs: string("{\"query\":\"what is this\"}")}
jsonMarshal(res)
jsoniterMarshal(res)
}