import (
"fmt"
jsoniter "github.com/json-iterator/go"
"testing"
)
type A struct {
B *B `json:"b"`
}
type B struct {
A *A `json:"a"`
}
func TestJSON(t *testing.T) {
var a = A{}
var b = B{}
a.B = &b
b.A = &a
var ji = jsoniter.ConfigCompatibleWithStandardLibrary
data, _ := ji.Marshal(a)
fmt.Println(string(data))
}
but official package can handle this issue normally
code:
import (
gojson "encoding/json"
"fmt"
"testing"
)
type A struct {
B *B `json:"b"`
}
type B struct {
A *A `json:"a"`
}
func TestJSON(t *testing.T) {
var a = A{}
var b = B{}
a.B = &b
b.A = &a
data, _ := gojson.Marshal(a)
fmt.Println(string(data))
}
follow code cause stack overflow
output:
but official package can handle this issue normally code:
out: