Stefan de Kraker
04/18/2024, 11:39 AMrouting {
route("/product") {
get("/all") {
call.respond(
status = HttpStatusCode.OK,
message = service.getAll()
)
}
}
}
class ProductService(private val productRepository: ProductRepository) {
fun getAll(): List<ProductEntity> {
return productRepository.getAll()
}
}
interface ProductRepository {
fun getAll(): List<ProductEntity>
}
class ProductRepositoryImpl : ProductRepository {
private val dotenv = dotenv()
private val database = Database.connect(
url = "jdbc:mysql://${dotenv["DB_HOST"]}:${dotenv["DB_PORT"]}/${dotenv["DB_NAME"]}${dotenv["DB_TYPE"]}",
driver = "com.mysql.jdbc.Driver",
user = dotenv["MYSQL_USER"],
password = dotenv["MYSQL_PASSWORD"]
)
override fun getAll(): List<ProductEntity> {
return emptyList()
}
}
java.lang.NoSuchMethodError: 'java.lang.Object io.ktor.serialization.ContentConverter.serializeNullable(io.ktor.http.ContentType, java.nio.charset.Charset, io.ktor.util.reflect.TypeInfo, java.lang.Object, kotlin.coroutines.Continuation)'
Israel Mendoza
04/18/2024, 5:15 PM// Serialization
implementation("io.ktor:ktor-server-content-negotiation-jvm")
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm")
You may need to install the plugin as well.
Then, add the following annotation on top of your ProductEntity data class:
@Serializable
data class ProductEntity(val id: Int, val name: String)
I hope this helps!Bruno Medeiros
04/20/2024, 2:57 AM