connect-kotlin
connect-kotlin copied to clipboard
Generated code does not map optional fields to Kotlin nullable variables
Hi,
One of the most annoying issues with GRPC in Kotlin is that the generated kotlin code does not work with optional
.
It generates the following code:
/**
* `optional uint32 min_transaction_amount_in_cents = 5 [json_name = "minTransactionAmountInCents"];`
*/
public var minTransactionAmountInCents: kotlin.Int
@JvmName("getMinTransactionAmountInCents")
get() = _builder.getMinTransactionAmountInCents()
@JvmName("setMinTransactionAmountInCents")
set(value) {
_builder.setMinTransactionAmountInCents(value)
}
/**
* `optional uint32 min_transaction_amount_in_cents = 5 [json_name = "minTransactionAmountInCents"];`
*/
public fun clearMinTransactionAmountInCents() {
_builder.clearMinTransactionAmountInCents()
}
/**
* `optional uint32 min_transaction_amount_in_cents = 5 [json_name = "minTransactionAmountInCents"];`
* @return Whether the minTransactionAmountInCents field is set.
*/
public fun hasMinTransactionAmountInCents(): kotlin.Boolean {
return _builder.hasMinTransactionAmountInCents()
}
Which means that you need to think about using the has
method to know if your field is present or not, because they set the default value. It's not the case with swift, rust or javascript
When I saw that connect-kotlin
was out, I was hopeful that you would have fixed this problem, but I saw that connectrpc/kotlin depended on protocolbuffers/kotlin and figured you would still have this issue. Confirmed after trying it.
Do you plan on fixing it or is it a behaviour you're okay with? Do you know if there's a solution (besides rewriting the files)?