silantev-ai opened a new issue, #2423: URL: https://github.com/apache/fory/issues/2423
### Question version: https://pkg.go.dev/github.com/apache/fory/go/[email protected]?tab=versions What is correct way to register a custom struct as array? Following example is working fine until I fill Example.Items field with values ```golang func example() { // region struct type Item struct { Name string } type Example struct { Items []Item } // endregion //region init fory fory := forygo.NewFory(true) if err := fory.RegisterTagType("Example", Example{}); err != nil { panic(err) } if err := fory.RegisterTagType("Item", Item{}); err != nil { panic(err) } // endregion // region example1 example1 := &Example{Items: []Item{}} fmt.Println(example1) bytes, _ := fory.Marshal(example1) var deserialized interface{} if err := fory.Unmarshal(bytes, &deserialized); err != nil { panic(err) } fmt.Println(deserialized) // endregion // region example2 example2 := &Example{Items: []Item{{Name: "name"}}} fmt.Println(example2) bytes, _ = fory.Marshal(example2) var deserialized2 interface{} if err := fory.Unmarshal(bytes, &deserialized2); err != nil { panic(err) } fmt.Println(deserialized2) // endregion } ``` ``` panic: reflect: New(nil) goroutine 13 [running]: reflect.New({0x0, 0x0}) /Users/aleks.silantev/go/pkg/mod/golang.org/[email protected]/src/reflect/value.go:2998 +0xf0 github.com/apache/fory/go/fory.sliceSerializer.readDifferentTypes({{{0x1050811b0, 0x104e84460}, {0x0, 0x0, 0x0}, 0x140005a4930, 0x140005a4990, 0x0, 0x11, 0x0, ...}}, ...) /Users/aleks.silantev/go/pkg/mod/github.com/apache/fory/go/[email protected]/slice.go:296 +0x268 github.com/apache/fory/go/fory.sliceSerializer.Read({{{0x1050811b0, 0x104e84460}, {0x0, 0x0, 0x0}, 0x140005a4930, 0x140005a4990, 0x0, 0x11, 0x0, ...}}, ...) /Users/aleks.silantev/go/pkg/mod/github.com/apache/fory/go/[email protected]/slice.go:247 +0x598 github.com/apache/fory/go/fory.(*Fory).readData(0x140002360a0, 0x14000236280, {0x104d83f80, 0x140005ba270, 0x197}, {0x1050776f0, 0x140005c2070}) /Users/aleks.silantev/go/pkg/mod/github.com/apache/fory/go/[email protected]/fory.go:447 +0xb0 github.com/apache/fory/go/fory.(*Fory).readReferencableBySerializer(0x140002360a0, 0x14000236280, {0x104d83f80, 0x140005ba270, 0x197}, {0x1050776f0, 0x140005c2070}) /Users/aleks.silantev/go/pkg/mod/github.com/apache/fory/go/[email protected]/fory.go:390 +0x1e8 github.com/apache/fory/go/fory.readBySerializer(0x140002360a0, 0x14000236280, {0x104d83f80, 0x140005ba270, 0x197}, {0x1050776f0, 0x140005c2070}, 0x1) /Users/aleks.silantev/go/pkg/mod/github.com/apache/fory/go/[email protected]/serializer.go:480 +0x6c github.com/apache/fory/go/fory.(*structSerializer).Read(0x14000236150, 0x140002360a0, 0x14000236280, {0x1050811b0, 0x104e844e0}, {0x104e844e0, 0x140005ba270, 0x199}) /Users/aleks.silantev/go/pkg/mod/github.com/apache/fory/go/[email protected]/struct.go:111 +0x560 github.com/apache/fory/go/fory.(*ptrToStructSerializer).Read(0x14000236140, 0x140002360a0, 0x14000236280, {0x1050811b0, 0x104d6c980}, {0x104d6c980, 0x140005aa118, 0x196}) /Users/aleks.silantev/go/pkg/mod/github.com/apache/fory/go/[email protected]/struct.go:332 +0x128 github.com/apache/fory/go/fory.(*Fory).readData(0x140002360a0, 0x14000236280, {0x104e24220, 0x14000596440, 0x194}, {0x1050776b8, 0x14000236140}) /Users/aleks.silantev/go/pkg/mod/github.com/apache/fory/go/[email protected]/fory.go:441 +0x3a4 github.com/apache/fory/go/fory.(*Fory).readReferencableBySerializer(0x140002360a0, 0x14000236280, {0x104e24220, 0x14000596440, 0x194}, {0x0, 0x0}) /Users/aleks.silantev/go/pkg/mod/github.com/apache/fory/go/[email protected]/fory.go:390 +0x1e8 github.com/apache/fory/go/fory.(*Fory).ReadReferencable(0x140002360a0, 0x14000236280, {0x104e24220, 0x14000596440, 0x194}) /Users/aleks.silantev/go/pkg/mod/github.com/apache/fory/go/[email protected]/fory.go:377 +0x50 github.com/apache/fory/go/fory.(*Fory).Deserialize(0x140002360a0, 0x14000236280, {0x104d6f900, 0x14000596440}, {0x0, 0x0, 0x0}) /Users/aleks.silantev/go/pkg/mod/github.com/apache/fory/go/[email protected]/fory.go:370 +0x358 github.com/apache/fory/go/fory.(*Fory).Unmarshal(0x140002360a0, {0x1400059e150, 0x1f, 0x30}, {0x104d6f900, 0x14000596440}) /Users/aleks.silantev/go/pkg/mod/github.com/apache/fory/go/[email protected]/fory.go:326 +0xf0 ``` Also It works fine with version: github.com/alipay/fury/go/fury v0.0.0-20231216032808-080e351f29fb // https://pkg.go.dev/github.com/google/fury?tab=versions -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
