mjson
mjson copied to clipboard
toString should produce parsable JSON by default
The current default implementation of Json.toString
will output an ellipsis (...
) when the traversal is about to output the same object (same Java reference). This is to avoid circularity issues and because the aim of toString
was for display purposes. We might break backward compatibility (and maybe this can be made optional), but this decision is a bit counter-intuitive. One expected toString to at least produce a valid JSON string. Because we set out to support graphs in this API and not just trees, we have to handle circular structures. But we can do this in a separate method, e.g. displayString
or some such. Alternatively, we could offer a hook to be provided by the user to deal with serializing the same object, but in a different context.