Open mrchantey opened 3 months ago
Yes, that is expected behaviour. RON is a superset of JSON, so all JSON documents are valid RON documents. But RON also supports structs and enums with a Rusty syntax, which is not supported by JSON. In your ron_to_json
function, you serialize a ron::Value
to JSON, which maps all RON-specific concepts down into JSON in a destructive process, e.g. MyStruct(name: "John", age: 32)
becomes {"name": "John", "age": 32}
. While RON can still parse this JSON document, it cannot convert it back to the original since a map is not a struct.
TLDR: RON can roundtrip JSON documents (through JSON and RON), but not RON documents through JSON.
Still, a reformulation of this issue is on my long-term TODO list. serde::Value
will get some love in a future release to allow all RON documents to roundtrip through it. Perhaps it could then also be given the ability to switch to a more verbose encoding when targeting a non-RON format such that RON -> ron::Value -> JSON -> ron::Value -> RON
could roundtrip ... but I'm still not 100% sure that this would work.
Ok that makes sense thanks for the explanation
It seems we can convert from RON to JSON but the inverse has unexpected behavior, calling
ron::to_string_pretty()
on aserde_json::Value
outputs json, not ron.