Эх сурвалжийг харах

Fix for JSON serialization of 0/empty-valued wrapper types (#7198)

* Fixed Ruby JSON serialization of 0/empty wrapper fields.

* Removed newly-passing conformance tests from the failure list.
Joshua Haberman 5 жил өмнө
parent
commit
f2c5ee5117

+ 0 - 18
conformance/failure_list_ruby.txt

@@ -94,25 +94,7 @@ Required.Proto3.JsonInput.IgnoreUnknownJsonObject.ProtobufOutput
 Required.Proto3.JsonInput.IgnoreUnknownJsonString.ProtobufOutput
 Required.Proto3.JsonInput.IgnoreUnknownJsonString.ProtobufOutput
 Required.Proto3.JsonInput.IgnoreUnknownJsonTrue.ProtobufOutput
 Required.Proto3.JsonInput.IgnoreUnknownJsonTrue.ProtobufOutput
 Required.Proto3.JsonInput.OneofFieldDuplicate
 Required.Proto3.JsonInput.OneofFieldDuplicate
-Required.Proto3.JsonInput.OptionalBoolWrapper.JsonOutput
-Required.Proto3.JsonInput.OptionalBytesWrapper.JsonOutput
-Required.Proto3.JsonInput.OptionalDoubleWrapper.JsonOutput
-Required.Proto3.JsonInput.OptionalFloatWrapper.JsonOutput
-Required.Proto3.JsonInput.OptionalInt32Wrapper.JsonOutput
-Required.Proto3.JsonInput.OptionalInt64Wrapper.JsonOutput
-Required.Proto3.JsonInput.OptionalStringWrapper.JsonOutput
-Required.Proto3.JsonInput.OptionalUint32Wrapper.JsonOutput
-Required.Proto3.JsonInput.OptionalUint64Wrapper.JsonOutput
 Required.Proto3.JsonInput.RejectTopLevelNull
 Required.Proto3.JsonInput.RejectTopLevelNull
-Required.Proto3.JsonInput.RepeatedBoolWrapper.JsonOutput
-Required.Proto3.JsonInput.RepeatedBytesWrapper.JsonOutput
-Required.Proto3.JsonInput.RepeatedDoubleWrapper.JsonOutput
-Required.Proto3.JsonInput.RepeatedFloatWrapper.JsonOutput
-Required.Proto3.JsonInput.RepeatedInt32Wrapper.JsonOutput
-Required.Proto3.JsonInput.RepeatedInt64Wrapper.JsonOutput
-Required.Proto3.JsonInput.RepeatedStringWrapper.JsonOutput
-Required.Proto3.JsonInput.RepeatedUint32Wrapper.JsonOutput
-Required.Proto3.JsonInput.RepeatedUint64Wrapper.JsonOutput
 Required.Proto3.JsonInput.StringFieldSurrogatePair.JsonOutput
 Required.Proto3.JsonInput.StringFieldSurrogatePair.JsonOutput
 Required.Proto3.JsonInput.StringFieldSurrogatePair.ProtobufOutput
 Required.Proto3.JsonInput.StringFieldSurrogatePair.ProtobufOutput
 Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput
 Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput

+ 3 - 2
ruby/ext/google/protobuf_c/encode_decode.c

@@ -1466,6 +1466,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc,
   MessageHeader* msg;
   MessageHeader* msg;
   upb_msg_field_iter i;
   upb_msg_field_iter i;
   upb_status status;
   upb_status status;
+  bool json_wrapper = is_wrapper(desc->msgdef) && is_json;
 
 
   if (is_json &&
   if (is_json &&
       upb_msgdef_wellknowntype(desc->msgdef) == UPB_WELLKNOWN_ANY) {
       upb_msgdef_wellknowntype(desc->msgdef) == UPB_WELLKNOWN_ANY) {
@@ -1542,7 +1543,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc,
         is_default = RSTRING_LEN(str) == 0;
         is_default = RSTRING_LEN(str) == 0;
       }
       }
 
 
-      if (is_matching_oneof || emit_defaults || !is_default) {
+      if (is_matching_oneof || emit_defaults || !is_default || json_wrapper) {
         putstr(str, f, sink);
         putstr(str, f, sink);
       }
       }
     } else if (upb_fielddef_issubmsg(f)) {
     } else if (upb_fielddef_issubmsg(f)) {
@@ -1562,7 +1563,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc,
     } else if (upb_msgdef_syntax(desc->msgdef) == UPB_SYNTAX_PROTO3) {       \
     } else if (upb_msgdef_syntax(desc->msgdef) == UPB_SYNTAX_PROTO3) {       \
       is_default = default_value == value;                                   \
       is_default = default_value == value;                                   \
     }                                                                        \
     }                                                                        \
-    if (is_matching_oneof || emit_defaults || !is_default) {                 \
+    if (is_matching_oneof || emit_defaults || !is_default || json_wrapper) { \
       upb_sink_put##upbtype(sink, sel, value);                               \
       upb_sink_put##upbtype(sink, sel, value);                               \
     }                                                                        \
     }                                                                        \
   } break;
   } break;

+ 1 - 0
ruby/tests/common_tests.rb

@@ -1293,6 +1293,7 @@ module CommonTests
     run_asserts.call(m)
     run_asserts.call(m)
     m2 = proto_module::Wrapper.decode(m.to_proto)
     m2 = proto_module::Wrapper.decode(m.to_proto)
     run_asserts.call(m2)
     run_asserts.call(m2)
+    m3 = proto_module::Wrapper.decode_json(m.to_json)
   end
   end
 
 
   def test_wrapper_getters
   def test_wrapper_getters