-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
package main
import (
"encoding/json"
"fmt"
"reflect"
jsoniter "github.com/json-iterator/go"
)
type Ttest map[string]string
func main() {
fn := func(name string, marshal func(interface{}) ([]byte, error), obj interface{}) []byte {
jb, err := marshal(obj)
if err != nil {
fmt.Printf("%s failed to marshal:\n error: %v\n", name, err)
return nil
}
return jb
}
var obj1 Ttest
jb1 := fn("json", json.Marshal, &obj1)
var obj2 Ttest
jb2 := fn("jsoniter", jsoniter.Marshal, &obj2)
if !reflect.DeepEqual(jb1, jb2) {
fmt.Printf("results differ:\n expected: %q\n got: %q\n", string(jb1), string(jb2))
}
}
yields:
results differ:
expected: "null"
got: "{}"
Changing map to slice also produces differences:
results differ:
expected: "null"
got: "[]"
Metadata
Metadata
Assignees
Labels
No labels