go
go copied to clipboard
JSON iter doesn't work properly with nil RawMessage
package main
import (
"encoding/json"
"fmt"
jsoniter "github.com/json-iterator/go"
)
func main() {
type A struct {
Rm jsoniter.RawMessage
}
a := A{}
b, e := jsoniter.Marshal(a)
fmt.Println("jsoniter: ",b, e)
e = jsoniter.Unmarshal(b, &a)
fmt.Println("jsoniter: ",e)
b, e = json.Marshal(a)
fmt.Println("json: ",b, e)
e = json.Unmarshal(b, &a)
fmt.Println("json: ",e)
}
https://play.golang.org/p/RoBEyZNxk-R
Fully symmetric comparison validates issue: https://play.golang.org/p/ydVcBDQsF5l
Hello. It's brake behavior to unmarshal null
value into RawMessage
https://play.golang.org/p/xDrMSSKyisZ
@AllenX2018 As mentioned by the preceding commenter, the changes introduced in https://github.com/json-iterator/go/commit/5bce16d299eb21bb5a80aa37151d805c37acd79d broke compatibility with unmarshaling of null
into a RawMessage
: the result is a nil byte slice, but the standard library would store the bytes null
instead.
Would it be possible to address this issue?