krotoDC 1.1.1 is out with json conversion support ...
# opensource
m
krotoDC 1.1.1 is out with json conversion support K 🦜 https://github.com/mscheong01/krotoDC For those who are tired of Java/Kotlin's protobuf's cumbersome null checks - Try krotoDC which supports data class Protobufs, nullable fields, implicit conversions to Kotlin standard library types, and more!
👀 1
j
sorry if the question is dumb, but what are the advantages compared to using the official Kotlin implementation?
👀 1
m
Hey @Johann Pardanaud, no worries at all! The main headache I've run into with the standard Kotlin implementation of Protobuf is that it doesn't handle nullable fields very well. When you're checking if the original Protobuf fields are null, you can't just compare them directly to null; you have to use the
has~()
functions instead. And when you want to assign null to a Protobuf field, it's not as straightforward as you might hope. Here's a quick example to illustrate:
Copy code
// Defining a Protobuf message
message person {
 optional string hobby = 1;
}

// Assigning a value
personKt = person {
 hobby = "climbing"
}

// Null check
if (person.hasHobby()) {
 // Do something
}

// Null assignment
val someHobby: String? = null
newPerson = person {
 if (someHobby == null) {
    hobby = someHobby
 }
}
This can get really cumbersome, especially when you're converting between your domain classes and Protobufs, because you can't directly assign null values to fields. But with krotoDC, this issue is a thing of the past since Protobuf fields are nullable from the get-go. There are also other perks to using krotoDC, like being able to use Java/Kotlin official types, like
LocalDateTime
, instead of Protobuf types like
Timestamp
or
oneof
sealed types, and so on. It's a bit more flexible and less frustrating to work with.
j
Thank you for the explanations :)
👍 1