Open milo2005 opened 7 years ago
DataObject.doc says setters shall return "this". Kotlin generates properties that return Unit (void). @Fluent properties required only for the vertx code generation.
I guess you are looking for a @DataObject
class to pass it through EventBus instead of JsonObject.
I found two ways to solve this:
Manually create set props (not a good thing in kotlin)
@DataObject(generateConverter = true)
class Author() {
private var _name: String = ""
private var _email: String = ""
fun getName(): String {
return _name
}
fun setName(value: String): Author {
_name = value
return this
}
fun getEmail(): String {
return _email
}
fun setEmail(value: String): Author {
_email = value
return this
}
constructor(json: JsonObject) : this() {
AuthorConverter.fromJson(json, this)
}
fun toJson(): JsonObject {
return JsonObject.mapFrom(this)
}
}
This way you can use generated <ClassName>Converter
.
Code generation works if there is package-info.java with the package marked @ModuleGen
.
I hope Jetbrains adds @Fluent
properties in kotlin somewhen.
Don't use code generation Remove the package from package-info.java and generateConverter param
@DataObject
class Author() {
lateinit var name: String
lateinit var email: String
constructor(json: JsonObject) : this() {
this.name = json.getString("name", "")
this.email = json.getString("email", "")
}
fun toJson(): JsonObject {
return JsonObject.mapFrom(this)
}
}
This way you need to set fields manually. Author can be passed through EventBus now.
I want to generate a data object from a kotlin class (Author), but it generates an error that I could not solve
Could not generate element for org.vult.services.Author: null
I think it may be because when generating the kotlin stub add annotations to the attributes and thus error in the generation of the converter.
EJ. @org.jetbrains.annotations.NotNull()
it is possible to generate from a kotlin class or is there an example?
This is my Gradle.Script
Author.kt
thanks