我有一个包含布尔字段的 protobuf 消息。当我将 false
值传递给请求中的布尔字段以及解析请求时,包含 false
值的字段将被忽略。例如下面:
message Features {
bool enable_config = 1;
bool enable_logo_on_screen = 2;
string custom_url = 3;
bool enable_footer = 4;
}
message UpdateFeaturesRequest {
Features features = 1;
}
假设 Features 对象已存在于包含以下值的数据库中:
{
enableConfig: true,enableLogoOnScreen: true,customUrl: "https://custom.url.uk/app",enableFooter: true
}
现在我想要一个可以更新功能的特定字段的 grpc 更新请求,所以当我像下面这样触发 UpdateFeaturesRequest
时:
{
enableConfig: false,customUrl: "https://custom2.url.hu/app"
}
预期的输出是在 DB 中具有更新的功能对象,例如:
{
enableConfig: false,customUrl: "https://custom2.url.hu/app",enableFooter: true
}
但不幸的是,我无法检测到 false
proto 消息中的 UpdateFeaturesRequest
值。我正在数据库中以 JSON 格式保存功能对象。
所以,当我这样做时:
updateFeaturesRequest.getFeatures()
然后布尔假值被忽略。我怎样才能让 UpdateFeaturesRequest
.
我必须知道 Json 格式化程序会忽略布尔假值,我们必须执行以下操作:
JsonFormat
.printer()
.includingDefaultvalueFields()
.print(message);
但这也包括 protobuf 消息中存在的其他默认值。我只想更新 UpdateFeaturesRequest
中存在的特定字段。有人可以帮忙吗。