Add --force-empty-vectors option (#5653)

The rationale for this option is that JSON clients typically want empty arrays (i.e [] in the JSON) instead of missing properties, but not empty strings when the value isn't set.
--force-empty is kept as-is, i.e. it will force both empty strings and vectors.

Closes #5652
This commit is contained in:
cryptocode
2019-12-06 02:33:45 +01:00
committed by Wouter van Oortmerssen
parent d7530ae961
commit a8e800bd7c
4 changed files with 102 additions and 89 deletions

View File

@@ -588,9 +588,13 @@ struct IDLOptions {
// for code generation.
unsigned long lang_to_generate;
// If set (default behavior), empty string and vector fields will be set to
// nullptr to make the flatbuffer more compact.
bool set_empty_to_null;
// If set (default behavior), empty string fields will be set to nullptr to make
// the flatbuffer more compact.
bool set_empty_strings_to_null;
// If set (default behavior), empty vector fields will be set to nullptr to make
// the flatbuffer more compact.
bool set_empty_vectors_to_null;
IDLOptions()
: use_flexbuffers(false),
@@ -635,7 +639,8 @@ struct IDLOptions {
lang(IDLOptions::kJava),
mini_reflect(IDLOptions::kNone),
lang_to_generate(0),
set_empty_to_null(true) {}
set_empty_strings_to_null(true),
set_empty_vectors_to_null(true) {}
};
// This encapsulates where the parser is in the current source file.