JSONStateWriter casts the pretty writer pointer to a regular writer, I'm not totally sure why this compiles given rapidjson::PrettyWriter extends rapidjson::Writer, however none of the methods are virtual. Hence, once the pointer is cast, all calls hit rapidjson::Writer and skip the pretty print prefixes.
This bug is not present in JSONLogger, but due to how JSONStateWriter is structured for partial outputs, it will need a more complex solution (e.g. factory and templated class, or two internal writer pointers being tested at use 🤮).
To Reproduce
Run IOTtest.JSON_WriteRead and breakpoint it after the file has been output (pretty print is enabled by default) and check test.json found in tests/.
Expected Behaviour
Pretty print output should be across multiple lines with indentation.
Additional Information
I'll probably write a fix tonight/tomorrow.
I'm not going to write a dedicated test for this, because that would require manually parsing the json and checking for newlines/tab, but I'm not that keen.
Bug Description
JSONStateWriter
casts the pretty writer pointer to a regular writer, I'm not totally sure why this compiles givenrapidjson::PrettyWriter
extendsrapidjson::Writer
, however none of the methods are virtual. Hence, once the pointer is cast, all calls hitrapidjson::Writer
and skip the pretty print prefixes.This bug is not present in
JSONLogger
, but due to howJSONStateWriter
is structured for partial outputs, it will need a more complex solution (e.g. factory and templated class, or two internal writer pointers being tested at use 🤮).To Reproduce
Run
IOTtest.JSON_WriteRead
and breakpoint it after the file has been output (pretty print is enabled by default) and checktest.json
found intests/
.Expected Behaviour
Pretty print output should be across multiple lines with indentation.
Additional Information
I'll probably write a fix tonight/tomorrow. I'm not going to write a dedicated test for this, because that would require manually parsing the json and checking for newlines/tab, but I'm not that keen.