> On Jan. 7, 2016, 10:25 a.m., Alexander Rukletsov wrote: > > 3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp, lines 97-99 > > <https://reviews.apache.org/r/41593/diff/14/?file=1181766#file1181766line97> > > > > Why this behaviour? I would expect if `set()` is not called, nothing is > > printed. If a field is optional, I can imagine some cases treating the > > absence of a value differently to `false`, effectively implementing tribool > > logic. > > > > Or am I understanding the workflow wrong? > > Michael Park wrote: > This behavior is consistent with other writers such as `ArrayWriter` > where not calling `append` results in `[]`. The provided expectation is that > a writer will always write something. If a field is optional and therefore we > want to omit writing under certain conditions, the pattern is to not invoke > the `write` at all. > > For exmaple, > ```cpp > 190 // Omit pid for http frameworks. > 191 if (framework.pid.isSome()) { > 192 writer->field("pid", string(framework.pid.get())); > 193 } > ``` > > Does this seem reasonable?
I see. First, almost no-one will use `BooleanWriter` directly, but rather indirectly via `JSON::ObjectWriter::field()`. Second the idea is once we create an object, we should add an entry in the JSON result. No entry — no object. Makes sense, since JSON does not allow empty values for fields AFAIK. Mind extending the example you have in the README with this approach for optional fields? > On Jan. 7, 2016, 10:25 a.m., Alexander Rukletsov wrote: > > 3rdparty/libprocess/3rdparty/stout/Makefile.am, line 38 > > <https://reviews.apache.org/r/41593/diff/14/?file=1181763#file1181763line38> > > > > Is formatting off or it's just review board? > > Michael Park wrote: > The formatting is off I think. I can't be sure with all of these tabs all > over the place. Yeah, it's a bit odd. In makefiles we align using tabs. - Alexander ----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: https://reviews.apache.org/r/41593/#review113230 ----------------------------------------------------------- On Jan. 8, 2016, 4:47 a.m., Michael Park wrote: > > ----------------------------------------------------------- > This is an automatically generated e-mail. To reply, visit: > https://reviews.apache.org/r/41593/ > ----------------------------------------------------------- > > (Updated Jan. 8, 2016, 4:47 a.m.) > > > Review request for mesos and Benjamin Hindman. > > > Repository: mesos > > > Description > ------- > > See summary. > > > Diffs > ----- > > 3rdparty/libprocess/3rdparty/stout/Makefile.am > 5ab7bc4966fe32eaddd573a4dbfd997f98b5d481 > 3rdparty/libprocess/3rdparty/stout/README.md > a2a3dc6120b10c8fe82088b9f0ebecfa5642f945 > 3rdparty/libprocess/3rdparty/stout/include/Makefile.am > b2dea9b93adfa3ea0415a0b5c81a369dd29b6cfe > 3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp PRE-CREATION > 3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp > 98ea47794b3a7c99b3cbd2418ba6e36eb5951259 > 3rdparty/libprocess/3rdparty/stout/tests/CMakeLists.txt > 62ad461eb228b688f1ceac16cfb003561ed5a806 > 3rdparty/libprocess/3rdparty/stout/tests/jsonify_tests.cpp PRE-CREATION > 3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp > bf2a2b8a9f67c6a4cf66b156b9c14fae015a8af0 > > Diff: https://reviews.apache.org/r/41593/diff/ > > > Testing > ------- > > Added tests to `<stout/jsonify_tests.cpp>` > > > Thanks, > > Michael Park > >