google / jsonapi

jsonapi.org style payload serializer and deserializer
http://godoc.org/github.com/google/jsonapi
MIT License
1.42k stars 211 forks source link

Stack overflow with many-to-many relationships #106

Open jackwilsdon opened 7 years ago

jackwilsdon commented 7 years ago

Is it possible to marshal a many-to-many relationship with jsonapi? I end up getting a stack overflow panic when trying to do so.

runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

runtime stack:
runtime.throw(0x4f5efb, 0xe)
    /usr/lib/go/src/runtime/panic.go:596 +0x95
runtime.newstack(0x0)
    /usr/lib/go/src/runtime/stack.go:1089 +0x3f2
runtime.morestack()
    /usr/lib/go/src/runtime/asm_amd64.s:398 +0x86

goroutine 1 [running]:
runtime.heapBitsSetType(0xc431465130, 0x50, 0x50, 0x4e8040)
    /usr/lib/go/src/runtime/mbitmap.go:894 +0x64b fp=0xc440100340 sp=0xc440100338
runtime.mallocgc(0x50, 0x4e8040, 0x1, 0x0)
    /usr/lib/go/src/runtime/malloc.go:723 +0x5c4 fp=0xc4401003e0 sp=0xc440100340
runtime.newobject(0x4e8040, 0x0)
    /usr/lib/go/src/runtime/malloc.go:820 +0x38 fp=0xc440100410 sp=0xc4401003e0
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:207 +0x70 fp=0xc4401007c0 sp=0xc440100410
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440100848 sp=0xc4401007c0
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440100bf8 sp=0xc440100848
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440100c80 sp=0xc440100bf8
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440101030 sp=0xc440100c80
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc4401010b8 sp=0xc440101030
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440101468 sp=0xc4401010b8
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc4401014f0 sp=0xc440101468
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc4401018a0 sp=0xc4401014f0
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440101928 sp=0xc4401018a0
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440101cd8 sp=0xc440101928
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440101d60 sp=0xc440101cd8
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440102110 sp=0xc440101d60
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440102198 sp=0xc440102110
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440102548 sp=0xc440102198
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc4401025d0 sp=0xc440102548
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440102980 sp=0xc4401025d0
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440102a08 sp=0xc440102980
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440102db8 sp=0xc440102a08
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440102e40 sp=0xc440102db8
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc4401031f0 sp=0xc440102e40
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440103278 sp=0xc4401031f0
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440103628 sp=0xc440103278
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc4401036b0 sp=0xc440103628
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440103a60 sp=0xc4401036b0
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440103ae8 sp=0xc440103a60
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440103e98 sp=0xc440103ae8
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440103f20 sp=0xc440103e98
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc4401042d0 sp=0xc440103f20
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440104358 sp=0xc4401042d0
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440104708 sp=0xc440104358
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440104790 sp=0xc440104708
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440104b40 sp=0xc440104790
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440104bc8 sp=0xc440104b40
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440104f78 sp=0xc440104bc8
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440105000 sp=0xc440104f78
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc4401053b0 sp=0xc440105000
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440105438 sp=0xc4401053b0
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc4401057e8 sp=0xc440105438
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440105870 sp=0xc4401057e8
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440105c20 sp=0xc440105870
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440105ca8 sp=0xc440105c20
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440106058 sp=0xc440105ca8
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc4401060e0 sp=0xc440106058
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440106490 sp=0xc4401060e0
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440106518 sp=0xc440106490
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc4401068c8 sp=0xc440106518
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440106950 sp=0xc4401068c8
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440106d00 sp=0xc440106950
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440106d88 sp=0xc440106d00
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440107138 sp=0xc440106d88
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc4401071c0 sp=0xc440107138
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440107570 sp=0xc4401071c0
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc4401075f8 sp=0xc440107570
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc4401079a8 sp=0xc4401075f8
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440107a30 sp=0xc4401079a8
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440107de0 sp=0xc440107a30
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440107e68 sp=0xc440107de0
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440108218 sp=0xc440107e68
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc4401082a0 sp=0xc440108218
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440108650 sp=0xc4401082a0
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc4401086d8 sp=0xc440108650
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440108a88 sp=0xc4401086d8
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440108b10 sp=0xc440108a88
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440108ec0 sp=0xc440108b10
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440108f48 sp=0xc440108ec0
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc4401092f8 sp=0xc440108f48
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440109380 sp=0xc4401092f8
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440109730 sp=0xc440109380
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc4401097b8 sp=0xc440109730
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440109b68 sp=0xc4401097b8
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc440109bf0 sp=0xc440109b68
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc440109fa0 sp=0xc440109bf0
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc44010a028 sp=0xc440109fa0
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc44010a3d8 sp=0xc44010a028
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc44010a460 sp=0xc44010a3d8
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc44010a810 sp=0xc44010a460
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc44010a898 sp=0xc44010a810
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc44010ac48 sp=0xc44010a898
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc44010acd0 sp=0xc44010ac48
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc44010b080 sp=0xc44010acd0
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc44010b108 sp=0xc44010b080
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc44010b4b8 sp=0xc44010b108
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc44010b540 sp=0xc44010b4b8
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc44010b8f0 sp=0xc44010b540
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc44010b978 sp=0xc44010b8f0
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc44010bd28 sp=0xc44010b978
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc44010bdb0 sp=0xc44010bd28
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc44010c160 sp=0xc44010bdb0
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc44010c1e8 sp=0xc44010c160
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc44010c598 sp=0xc44010c1e8
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc44010c620 sp=0xc44010c598
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc44010c9d0 sp=0xc44010c620
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc280, 0xc4200142e8, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc280)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc44010ca58 sp=0xc44010c9d0
github.com/google/jsonapi.visitModelNode(0x4c8de0, 0xc4200142d0, 0xc4600ffca8, 0x4c8d01, 0xc4200142d0, 0xc42000e430, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc44010ce08 sp=0xc44010ca58
github.com/google/jsonapi.visitModelNodeRelationships(0x4cc2c0, 0xc420014288, 0x197, 0xc4600ffca8, 0x1, 0x0, 0x2, 0x4cc2c0)
    /home/jack/go/src/github.com/google/jsonapi/response.go:487 +0x116 fp=0xc44010ce90 sp=0xc44010ce08
github.com/google/jsonapi.visitModelNode(0x4c8da0, 0xc420014270, 0xc4600ffca8, 0x4c8d01, 0xc420014270, 0xc42000e420, 0x196)
    /home/jack/go/src/github.com/google/jsonapi/response.go:390 +0x1bc8 fp=0xc44010d240 sp=0xc44010ce90
...additional frames elided...
exit status 2
package main

import (
    "bytes"
    "fmt"
    "github.com/google/jsonapi"
    "os"
)

type Post struct {
    ID      int       `jsonapi:"primary,posts"`
    Title   string    `jsonapi:"attr,name"`
    Authors []*Author `jsonapi:"relation,authors"`
}

type Author struct {
    ID    int     `jsonapi:"primary,authors"`
    Name  string  `jsonapi:"attr,name"`
    Posts []*Post `jsonapi:"relation,posts"`
}

func main() {
    jack := Author{
        ID:   1,
        Name: "Jack Wilsdon",
    }

    john := Author{
        ID:   2,
        Name: "John O'Connors",
    }

    marshal := Post{
        ID:      1,
        Title:   "Marshalling into JSON",
        Authors: []*Author{&jack, &john},
    }

    weather := Post{
        ID:      2,
        Title:   "Go 101",
        Authors: []*Author{&jack},
    }

    jack.Posts = []*Post{&marshal, &weather}
    john.Posts = []*Post{&marshal}

    buffer := bytes.Buffer{}

    if err := jsonapi.MarshalPayload(&buffer, &jack); err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    fmt.Println(buffer.String())
}
aren55555 commented 7 years ago

With the current implementation unfortunately what you want is not possible. Here is why; when traversing a struct's relations the library has no idea what it has or hasn't already visited. Therefore when serializing a many to many it gets stuck in an infinite loop until eventually the stack frame limit has been exceeded.

To fix this we need to store the things that have already been visited and serialized. If they are encountered again they should be ignored.

dcoxall commented 7 years ago

@aren55555 I've just encountered this same issue. Any hint as to the best place to look in order to try and create a PR to fix