go
go copied to clipboard
Prevent panic on self-referencing structs/map/slices during Marshal
This PR fixes a bug in Marshal where it would panic when attempting to serialize self-referencing structs or slices.
Previously, encountering these data structures would cause a panic, making it difficult to handle these situations gracefully. This change modifies Marshal to return an error instead, providing a more consistent and predictable way to handle serialization errors. This aligns the behavior with json.Marshal, which also returns an error when encountering self-referencing data structures.
This improvement enhances the robustness of the library and makes it easier to handle potential errors during serialization.