Skip to content

Commit

Permalink
revert 'Made it possible to drop null placeholders from array output.'
Browse files Browse the repository at this point in the history
revert ae3c7a7
  • Loading branch information
cdunn2001 committed Apr 11, 2015
1 parent 254fe6a commit 6f6ddaa
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 25 deletions.
8 changes: 0 additions & 8 deletions include/json/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,6 @@ class JSON_API FastWriter : public Writer {

void enableYAMLCompatibility();

/** \brief Drop the "null" string from the writer's output for nullValues.
* Strictly speaking, this is not valid JSON. But when the output is being
* fed to a browser's Javascript, it makes for smaller output and the
* browser can handle the output just fine.
*/
void dropNullPlaceholders();

public: // overridden from Writer
virtual std::string write(const Value& root);

Expand All @@ -173,7 +166,6 @@ class JSON_API FastWriter : public Writer {

std::string document_;
bool yamlCompatiblityEnabled_;
bool dropNullPlaceholders_;
};

/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a
Expand Down
7 changes: 2 additions & 5 deletions src/lib_json/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,10 @@ Writer::~Writer() {}
// //////////////////////////////////////////////////////////////////

FastWriter::FastWriter()
: yamlCompatiblityEnabled_(false), dropNullPlaceholders_(false) {}
: yamlCompatiblityEnabled_(false) {}

void FastWriter::enableYAMLCompatibility() { yamlCompatiblityEnabled_ = true; }

void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; }

std::string FastWriter::write(const Value& root) {
document_ = "";
writeValue(root);
Expand All @@ -300,8 +298,7 @@ std::string FastWriter::write(const Value& root) {
void FastWriter::writeValue(const Value& value) {
switch (value.type()) {
case nullValue:
if (!dropNullPlaceholders_)
document_ += "null";
document_ += "null";
break;
case intValue:
document_ += valueToString(value.asLargestInt());
Expand Down
12 changes: 0 additions & 12 deletions src/test_lib_json/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1618,17 +1618,6 @@ JSONTEST_FIXTURE(ValueTest, zeroesInKeys) {
}
}

struct WriterTest : JsonTest::TestCase {};

JSONTEST_FIXTURE(WriterTest, dropNullPlaceholders) {
Json::FastWriter writer;
Json::Value nullValue;
JSONTEST_ASSERT(writer.write(nullValue) == "null\n");

writer.dropNullPlaceholders();
JSONTEST_ASSERT(writer.write(nullValue) == "\n");
}

struct StreamWriterTest : JsonTest::TestCase {};

JSONTEST_FIXTURE(StreamWriterTest, dropNullPlaceholders) {
Expand Down Expand Up @@ -2286,7 +2275,6 @@ int main(int argc, const char* argv[]) {
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroes);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroesInKeys);

JSONTEST_REGISTER_FIXTURE(runner, WriterTest, dropNullPlaceholders);
JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, dropNullPlaceholders);
JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, writeZeroes);

Expand Down

0 comments on commit 6f6ddaa

Please sign in to comment.