Skip to content

Commit 09fcd0a

Browse files
committed
revert 'Made it possible to drop null placeholders from array output.'
revert ae3c7a7
1 parent eac41ec commit 09fcd0a

File tree

3 files changed

+2
-25
lines changed

3 files changed

+2
-25
lines changed

include/json/writer.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,6 @@ class JSON_API FastWriter : public Writer {
153153

154154
void enableYAMLCompatibility();
155155

156-
/** \brief Drop the "null" string from the writer's output for nullValues.
157-
* Strictly speaking, this is not valid JSON. But when the output is being
158-
* fed to a browser's Javascript, it makes for smaller output and the
159-
* browser can handle the output just fine.
160-
*/
161-
void dropNullPlaceholders();
162-
163156
public: // overridden from Writer
164157
virtual std::string write(const Value& root);
165158

@@ -168,7 +161,6 @@ class JSON_API FastWriter : public Writer {
168161

169162
std::string document_;
170163
bool yamlCompatiblityEnabled_;
171-
bool dropNullPlaceholders_;
172164
};
173165

174166
/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a

src/lib_json/json_writer.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,10 @@ Writer::~Writer() {}
192192
// //////////////////////////////////////////////////////////////////
193193

194194
FastWriter::FastWriter()
195-
: yamlCompatiblityEnabled_(false), dropNullPlaceholders_(false) {}
195+
: yamlCompatiblityEnabled_(false) {}
196196

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

199-
void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; }
200-
201199
std::string FastWriter::write(const Value& root) {
202200
document_ = "";
203201
writeValue(root);
@@ -208,8 +206,7 @@ std::string FastWriter::write(const Value& root) {
208206
void FastWriter::writeValue(const Value& value) {
209207
switch (value.type()) {
210208
case nullValue:
211-
if (!dropNullPlaceholders_)
212-
document_ += "null";
209+
document_ += "null";
213210
break;
214211
case intValue:
215212
document_ += valueToString(value.asLargestInt());

src/test_lib_json/main.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,17 +1497,6 @@ JSONTEST_FIXTURE(ValueTest, typeChecksThrowExceptions) {
14971497
#endif
14981498
}
14991499

1500-
struct WriterTest : JsonTest::TestCase {};
1501-
1502-
JSONTEST_FIXTURE(WriterTest, dropNullPlaceholders) {
1503-
Json::FastWriter writer;
1504-
Json::Value nullValue;
1505-
JSONTEST_ASSERT(writer.write(nullValue) == "null\n");
1506-
1507-
writer.dropNullPlaceholders();
1508-
JSONTEST_ASSERT(writer.write(nullValue) == "\n");
1509-
}
1510-
15111500
struct StreamWriterTest : JsonTest::TestCase {};
15121501

15131502
JSONTEST_FIXTURE(StreamWriterTest, dropNullPlaceholders) {
@@ -1841,7 +1830,6 @@ int main(int argc, const char* argv[]) {
18411830
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, compareType);
18421831
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, typeChecksThrowExceptions);
18431832

1844-
JSONTEST_REGISTER_FIXTURE(runner, WriterTest, dropNullPlaceholders);
18451833
JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, dropNullPlaceholders);
18461834

18471835
JSONTEST_REGISTER_FIXTURE(runner, ReaderTest, parseWithNoErrors);

0 commit comments

Comments
 (0)