gpt4 book ai didi

java - 如何转换 java.util.Map 中的 google.protobuf.Struct 字段?

转载 作者:行者123 更新时间:2023-12-05 07:07:15 24 4
gpt4 key购买 nike

我有一条消息定义的 quotation_item.proto 文件,其中包含用于解析元数据 JSON 的 google.protobuf.Struct 字段。

message QuotationItemEntry {
// Other fields
google.protobuf.Struct metadata = 15;
}

元数据字段也在Java实体类中定义

public class QuotationItem {
// Other entity fields
private Map<String, Object> metadata;
}

我想使用 spring boot 应用程序存储在 gRPC 请求中传递的 QuotationItemEntry 对象,但无法转换 google.protobuf.Struct java.util.Map<String, Object> 中的字段.

最佳答案

在 Java 中,google.protobuf.Struct的字段值在其 native 表示中不受支持。相反,它们被 com.google.protobuf.Value 包裹着.所以用 google.protobuf.Struct#getFieldsMap()方法,结果是 Map<String, Value> .您需要手动填充条目值。

关于java - 如何转换 java.util.Map<String, Object> 中的 google.protobuf.Struct 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62236577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com