Validate C# json/object-api options (#6985)
authorDerek Bailey <derekbailey@google.com>
Mon, 13 Dec 2021 19:52:01 +0000 (11:52 -0800)
committerGitHub <noreply@github.com>
Mon, 13 Dec 2021 19:52:01 +0000 (11:52 -0800)
docs/source/CsharpUsage.md
scripts/generate_code.py
src/flatc.cpp

index 83f4842..abfcbf6 100644 (file)
@@ -180,7 +180,8 @@ To use:
 An additional feature of the object API is the ability to allow you to
 serialize & deserialize a JSON text.
 To use Json Serialization, add `--cs-gen-json-serializer` option to `flatc` and
-add `Newtonsoft.Json` nuget package to csproj.
+add `Newtonsoft.Json` nuget package to csproj. This requires explicitly setting
+the `--gen-object-api` option as well.
 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
     // Deserialize MonsterT from json
@@ -192,7 +193,7 @@ add `Newtonsoft.Json` nuget package to csproj.
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 * Limitation
-  * `hash` attribute currentry not supported.
+  * `hash` attribute currently not supported.
 * NuGet package Dependency
   * [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)
 
index 7a667d8..39b8285 100755 (executable)
@@ -74,7 +74,7 @@ def flatc(
     cmd += [schema] if isinstance(schema, str) else schema
     if data:
         cmd += [data] if isinstance(data, str) else data
-    subprocess.run(cmd, cwd=cwd)
+    result = subprocess.run(cmd, cwd=cwd, check=True)
 
 
 # Glob a pattern relative to file path
index f278dab..6b9fdc0 100644 (file)
@@ -184,6 +184,8 @@ std::string FlatCompiler::GetUsageString(const char *program_name) const {
     "                         data using schema-less FlexBuffers.\n"
     "  --no-warnings          Inhibit all warning messages.\n"
     "  --cs-global-alias      Prepend \"global::\" to all user generated csharp classes and structs.\n"
+    "  --cs-gen-json-serializer Allows (de)serialization of JSON text in the Object\n"
+    "                           API. (requires --gen-object-api).\n"
     "FILEs may be schemas (must end in .fbs), binary schemas (must end in .bfbs),\n"
     "or JSON files (conforming to preceding schema). FILEs after the -- must be\n"
     "binary flatbuffer format files.\n"
@@ -435,6 +437,12 @@ int FlatCompiler::Compile(int argc, const char **argv) {
     Error("no options: specify at least one generator.", true);
   }
 
+  if (opts.cs_gen_json_serializer && !opts.generate_object_based_api) {
+    Error(
+        "--cs-gen-json-serializer requires --gen-object-api to be set as "
+        "well.");
+  }
+
   flatbuffers::Parser conform_parser;
   if (!conform_to_schema.empty()) {
     std::string contents;