THRIFT-3656 incorrect serialization of optionals
Client: Dart
Patch: Jens Geyer
diff --git a/compiler/cpp/src/generate/t_dart_generator.cc b/compiler/cpp/src/generate/t_dart_generator.cc
index 3333d16..7bae327 100644
--- a/compiler/cpp/src/generate/t_dart_generator.cc
+++ b/compiler/cpp/src/generate/t_dart_generator.cc
@@ -1010,6 +1010,11 @@
 
   for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
     string field_name = get_field_name((*f_iter)->get_name());
+    bool could_be_unset = (*f_iter)->get_req() == t_field::T_OPTIONAL;
+    if (could_be_unset) {
+      indent(out) << "if (" << generate_isset_check(*f_iter) << ")";
+      scope_up(out);
+    }
     bool null_allowed = type_can_be_null((*f_iter)->get_type());
     if (null_allowed) {
       indent(out) << "if (this." << field_name << " != null)";
@@ -1028,6 +1033,9 @@
     if (null_allowed) {
       scope_down(out);
     }
+    if (could_be_unset) {
+      scope_down(out);
+    }
   }
   // Write the struct map
   indent(out) << "oprot.writeFieldStop();" << endl << indent() << "oprot.writeStructEnd();"