mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 12:05:50 +00:00
Implement optional scalars for JSON (#7322)
* Implement optional scalars for JSON * Add optional scalars JSON test * Extend JSON optional scalars test to test without defaults * Fix optional scalars in JSON for binary schema Co-authored-by: Caleb Zulawski <caleb.zulawski@caci.com>
This commit is contained in:
@@ -1335,10 +1335,18 @@ CheckedError Parser::ParseTable(const StructDef &struct_def, std::string *value,
|
||||
ECHECK(atot(field_value.constant.c_str(), *this, &val)); \
|
||||
builder_.PushElement(val); \
|
||||
} else { \
|
||||
CTYPE val, valdef; \
|
||||
ECHECK(atot(field_value.constant.c_str(), *this, &val)); \
|
||||
ECHECK(atot(field->value.constant.c_str(), *this, &valdef)); \
|
||||
builder_.AddElement(field_value.offset, val, valdef); \
|
||||
if (field->IsScalarOptional()) { \
|
||||
if (field_value.constant != "null") { \
|
||||
CTYPE val; \
|
||||
ECHECK(atot(field_value.constant.c_str(), *this, &val)); \
|
||||
builder_.AddElement(field_value.offset, val); \
|
||||
} \
|
||||
} else { \
|
||||
CTYPE val, valdef; \
|
||||
ECHECK(atot(field_value.constant.c_str(), *this, &val)); \
|
||||
ECHECK(atot(field->value.constant.c_str(), *this, &valdef)); \
|
||||
builder_.AddElement(field_value.offset, val, valdef); \
|
||||
} \
|
||||
} \
|
||||
break;
|
||||
FLATBUFFERS_GEN_TYPES_SCALAR(FLATBUFFERS_TD)
|
||||
@@ -2469,7 +2477,7 @@ bool Parser::SupportsOptionalScalars(const flatbuffers::IDLOptions &opts) {
|
||||
IDLOptions::kRust | IDLOptions::kSwift | IDLOptions::kLobster |
|
||||
IDLOptions::kKotlin | IDLOptions::kCpp | IDLOptions::kJava |
|
||||
IDLOptions::kCSharp | IDLOptions::kTs | IDLOptions::kBinary |
|
||||
IDLOptions::kGo | IDLOptions::kPython;
|
||||
IDLOptions::kGo | IDLOptions::kPython | IDLOptions::kJson;
|
||||
unsigned long langs = opts.lang_to_generate;
|
||||
return (langs > 0 && langs < IDLOptions::kMAX) && !(langs & ~supported_langs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user