提问人:Abenstex 提问时间:11/14/2023 最后编辑:Abenstex 更新时间:11/14/2023 访问量:36
更新消息后反序列化不再正常工作
Deserialization not working properly anymore after updating message
问:
也许我不再看到树木的森林了,如果我看到了,我很抱歉,但我现在已经被困在一个问题上几个小时了。我通过添加一个字段(includeObsolete)更新了我的原型文件中的消息:
message GetAllDocumentsRequest {
RequestHeader header = 1;
bool include_obsolete= 2;
}
据我所知,相应的代码是正确构建的(至少我可以访问 GetAllDocumentsRequest 中的字段 include_obsolete),但是每当我在 grpc 服务中打印请求时,字段 include_obsolete 都设置为 .false
async fn get_all_documents(
&self,
request: Request<GetAllDocumentsRequest>,
) -> Result<Response<GetDocumentsReply>, Status> {
println!("Request: {:?}", request); // here include_obsolete is always false
foo();
bar();
...
这是我在 Postman 中使用的请求:
{
"include_obsolete": true,
"header": {
"comment": {
"actionType": "action",
"comment": "elit sit esse",
"createdBy": "in dolore enim",
"createdDate": "3410",
"ID": 45
},
"messageType": "officia est",
"senderAddress": "aute sed irure anim labore",
"senderId": "mollit sunt",
"token": "dolore dolor",
"user": "erwin"
}
}
作为参考,println!的输出:
Request: Request { metadata: MetadataMap { headers: {"grpc-accept-encoding": "identity,deflate,gzip", "accept-encoding": "identity", "user-agent": "grpc-node-js/1.8.10", "content-type": "application/grpc", "te": "trailers"} }, message: GetAllDocumentsRequest { header: Some(RequestHeader { sender_address: "aute sed irure anim labore", sender_id: "mollit sunt", user: "erwin", comment: Some(Comment { id: 45, created_date: 3410, created_by: "in dolore enim", action_type: "action", comment: "elit sit esse" }), message_type: Some("officia est"), token: Some("dolore dolor") }), include_obsolete: false }, extensions: Extensions }
每当我更改请求中的值时,所有其他字段都会正确打印。 我也试过把货物清理干净,但没有成功。
答:
0赞
Abenstex
11/14/2023
#1
问题实际上出在 Postman 上,因为无论出于何种原因,它都没有发送 JSON 请求的更新版本,而只是跳过了新添加的字段。重新导入 API 后,它起作用了。
评论