Test Fory's serialization and deserialization of a struct with a slice of nested structs.
(t *testing.T)
| 754 | |
| 755 | // Test Fory's serialization and deserialization of a struct with a slice of nested structs. |
| 756 | func TestStructWithNestedSlice(t *testing.T) { |
| 757 | type Item struct { |
| 758 | Name string |
| 759 | } |
| 760 | |
| 761 | type Example struct { |
| 762 | Items []Item |
| 763 | } |
| 764 | |
| 765 | fory := NewFory(WithXlang(true), WithCompatible(false), WithRefTracking(true)) |
| 766 | if err := fory.RegisterStructByName(Example{}, "Example"); err != nil { |
| 767 | panic(err) |
| 768 | } |
| 769 | if err := fory.RegisterStructByName(Item{}, "Item"); err != nil { |
| 770 | panic(err) |
| 771 | } |
| 772 | |
| 773 | example := &Example{Items: []Item{ |
| 774 | {Name: "test"}, |
| 775 | }} |
| 776 | bytes, _ := fory.Marshal(example) |
| 777 | var deserialized2 any |
| 778 | if err := fory.Unmarshal(bytes, &deserialized2); err != nil { |
| 779 | panic(err) |
| 780 | } |
| 781 | // When unmarshaling to any, named structs are returned as pointers |
| 782 | // for circular reference support |
| 783 | require.Equal(t, deserialized2, example) |
| 784 | } |
| 785 | |
| 786 | func convertRecursively(newVal, tmplVal reflect.Value) (reflect.Value, error) { |
| 787 | // Unwrap any any |
nothing calls this directly
no test coverage detected