From 4e470d3221bf59e4c51d5f0604317b7c6def94c0 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@41a61cd8-c433-0410-bb1c-e256eeef9e11> Date: Wed, 24 Oct 2007 02:57:30 +0000 Subject: [PATCH] r1302@dev030 (orig r65083): mcslee | 2007-10-23 19:56:24 -0700 Make the Java generator respect the optional keyword in struct writers Reviewed By: dreiss Test Plan: Generate Java code. Check functionality and safe compile git-svn-id: http://svn.facebook.com/svnroot/thrift/trunk@636 41a61cd8-c433-0410-bb1c-e256eeef9e11 --- compiler/cpp/src/generate/t_java_generator.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc index ea27854..0bfab75 100644 --- a/compiler/cpp/src/generate/t_java_generator.cc +++ b/compiler/cpp/src/generate/t_java_generator.cc @@ -566,6 +566,11 @@ void t_java_generator::generate_java_struct_writer(ofstream& out, indent() << "if (this." << (*f_iter)->get_name() << " != null) {" << endl; indent_up(); } + bool optional = bean_style_ && (*f_iter)->get_req() == t_field::OPTIONAL; + if (optional) { + out << + indent() << "if (this.__isset." << (*f_iter)->get_name() << ") {" << endl; + } out << indent() << "field.name = \"" << (*f_iter)->get_name() << "\";" << endl << @@ -580,6 +585,10 @@ void t_java_generator::generate_java_struct_writer(ofstream& out, indent(out) << "oprot.writeFieldEnd();" << endl; + if (optional) { + indent_down(); + indent(out) << "}" << endl; + } if (null_allowed) { indent_down(); indent(out) << "}" << endl; -- 2.11.4.GIT