From 5de28c74f9131f437e407be147c221b57c6eca7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Reimer?= <git@bjrm.de>
Date: Tue, 8 Sep 2015 11:00:35 +0200
Subject: [PATCH] serialize boolean in JSON to "true/false" instead of "0/1"

Change-Id: I90cf519c00eaf9ccd9fcab8035a91b9205587c3b
---
 src/idl_gen_text.cpp | 7 ++++++-
 tests/test.cpp       | 5 +++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/idl_gen_text.cpp b/src/idl_gen_text.cpp
index e26d93ca..52987af2 100644
--- a/src/idl_gen_text.cpp
+++ b/src/idl_gen_text.cpp
@@ -60,7 +60,12 @@ template<typename T> void Print(T val, Type type, int /*indent*/,
       return;
     }
   }
-  text += NumToString(val);
+
+  if (type.base_type == BASE_TYPE_BOOL) {
+    text += val ? "true" : "false";
+  } else {
+    text += NumToString(val);
+  }
 }
 
 // Print a vector a sequence of JSON values, comma separated, wrapped in "[]".
diff --git a/tests/test.cpp b/tests/test.cpp
index 116068ed..be008180 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -635,6 +635,11 @@ void FuzzTest2() {
             Dummy();
           }
           break;
+        case flatbuffers::BASE_TYPE_BOOL:
+          AddToSchemaAndInstances("bool", deprecated
+                                  ? ""
+                                  : (lcg_rand() % 2 ? "true" : "false"));
+          break;
         default:
           // All the scalar types.
           schema += flatbuffers::kTypeNames[base_type];
-- 
GitLab