Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

circular data structures when encoding #199

Closed
cloverstd opened this issue Nov 24, 2017 · 4 comments
Closed

circular data structures when encoding #199

cloverstd opened this issue Nov 24, 2017 · 4 comments

Comments

@cloverstd
Copy link

package main

import jsoniter "github.com/json-iterator/go"

var json = jsoniter.ConfigCompatibleWithStandardLibrary

func main() {

	a := &A{}
	a.B1 = &B{a}
	ping := &Ping{a}

	json.Marshal(ping)

}

type Ping struct {
	Pong *A
}

type A struct {
	B1 *B
}

type B struct {
	A1 *A
}

This code will panic with runtime: goroutine stack exceeds 1000000000-byte limit

Platform: go version go1.9 darwin/amd64

ref golang/go#10769

@taowen
Copy link
Contributor

taowen commented Nov 30, 2017

jsoniter is compatible with encoding/json. If this is fixed in encoding/json, I will fix it as well.

Tracking recursion is possible in user extension, for example: https://github.com/v2pro/plz/blob/master/witch/exporter.go

The Attachment field in Stream and Iterator is added to support this kind of tracking

@taowen taowen closed this as completed Nov 30, 2017
@MoZhonghua
Copy link

@taowen this has been fixed in encoding/json, see https://go-review.googlesource.com/c/go/+/187920

@machooo-x
Copy link

It is still not supported.

@WenRuige
Copy link

It is still not supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants