Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions ruby/ext/google/protobuf_c/encode_decode.c
Expand Up @@ -1466,6 +1466,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc,
MessageHeader* msg;
upb_msg_field_iter i;
upb_status status;
bool json_wrapper = is_wrapper(desc->msgdef) && is_json;

if (is_json &&
upb_msgdef_wellknowntype(desc->msgdef) == UPB_WELLKNOWN_ANY) {
Expand Down Expand Up @@ -1542,7 +1543,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc,
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);
}
} else if (upb_fielddef_issubmsg(f)) {
Expand All @@ -1562,7 +1563,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc,
} else if (upb_msgdef_syntax(desc->msgdef) == UPB_SYNTAX_PROTO3) { \
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); \
} \
} break;
Expand Down
1 change: 1 addition & 0 deletions ruby/tests/common_tests.rb
Expand Up @@ -1293,6 +1293,7 @@ def test_wrappers_set_to_default
run_asserts.call(m)
m2 = proto_module::Wrapper.decode(m.to_proto)
run_asserts.call(m2)
m3 = proto_module::Wrapper.decode_json(m.to_json)
end

def test_wrapper_getters
Expand Down