set_always_print_primitive_fields will serialize all oneof data.
- Dominant language
- C++
- Stars
- 17.6k
- Forks
- 4.1k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 69
Description
**Describe the bug (描述bug)**
there is proto3 message
message Oneof {
oneof data {
string str1 = 1;
string str2 = 2;
}
};
message AA {
uint32 b=1;
Oneof c = 2;
};
and aa is an response to a restful service.
And my b's right value is 0,so i use cntl->set_always_print_primitive_fields(true); to serialize b.
but i find all of c are serialized though i only set the str1 value.
中文:
因为proto3不会序列化值位default的值,所以我使用了set_always_print_primitive_fields 这个函数。但是我的message里面会有oneof类型,所以我发现所有oneof类型里面包含的都被序列化了。但是我觉得oneof类型应该只序列化我们设的值
So the json reponse is :
{
"b": 0,
"service_result": {
"str1":"xxx",
"str2":""
}
}
**To Reproduce (复现方法)**
**Expected behavior (期望行为)**
I think set_always_print_primitive_fields should not serialize oneof data
**Versions (各种版本)**
OS:centos7
Compiler:gcc11
brpc:1.3.0
protobuf:3
**Additional context/screenshots (更多上下文/截图)**
Contributor guide
Research direction
Start by reproducing the issue with the Oneof and AA messages shown, using brpc 1.3.0 and protobuf 3, then trace the implementation of set_always_print_primitive_fields. Done means primitive default fields such as b are serialized while only the active oneof field, such as str1, appears in the JSON response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100