上下文:我想设计一个包含货币字段的原型文件,它将在gRPC服务响应中使用。我在努力追随this tutorial
我得到了这个错误
Type mismatch.
Required:
GeneratedMessageV3.Builder<*>!
Found:String它清楚地告诉我必须使用GeneratedMessageV3.Builder,但我不知道如何做到这一点。
这就是原型
syntax = "proto3";
package com.mycomp.adapters.grpc.test;
import "google/api/annotations.proto";
import "google/type/money.proto";
service TestService {
rpc GetTest (GetTestRequest) returns (Test) {
}
}
message GetTestRequest{
string id_cliente = 1;
}
message Test {
string id_cliente = 1;
google.type.Money test_money = 2;
}我是如何实现服务的,以及初始化一个非常简单的com.google.type.Money变量的问题。
import com.google.type.Money
...other imports
@Singleton
class TestEndpoint() : TestServiceGrpcKt.TestServiceCoroutineImplBase() {
override suspend fun getTest(request: GetTestRequest): Test {
val test = Test.newBuilder()
...
test.testMoney = Money("999.99") //*** certainly my mistake is here
return test.build()
}如果与之相关,下面是build.gradle最重要的部分
dependencies {
implementation("io.micronaut:micronaut-validation")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
implementation("io.micronaut:micronaut-runtime")
runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("io.micronaut:micronaut-http-client")
implementation ("com.google.api.grpc:proto-google-common-protos:1.0.0")
}我知道在proto文件中使用import "google/api/annotations.proto“和在Kotlin中导入com.google.type.Money所需要的唯一依赖项是
com.google.api.grpc:proto-google-common-protos:1.0.0发布于 2020-12-25 01:34:50
如果我对the javadoc的解释是正确的,那么您不能直接实例化Money类。取而代之的是使用如下内容:
test.testMoney = Money.newBuilder()
.setCurrencyCode("USD")
.setUnits(999)
.build();https://stackoverflow.com/questions/65441428
复制相似问题