I have a small Kotling resource, where I want to return a JSON representation of a class, but it seems to return some strange format:
CatFact(fact=This is a cat, length=2)
This resource is run in a Quarkus application with RESTEasy. Could that be the issue? I was assuming that this resource should map the object to JSON automatically:
package org.polychat.resources
import com.fasterxml.jackson.annotation.JsonProperty
import jakarta.ws.rs.GET
import jakarta.ws.rs.Path
import jakarta.ws.rs.Produces
import jakarta.ws.rs.core.MediaType
data class CatFact(
@JsonProperty("fact") val fact: String,
@JsonProperty("length") val length: Int,
)
@Path("/kotlin")
class KotlinResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
fun helloKotlin() = "Hello from Kotlin RESTEasy Reactive"
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/catfact")
fun catFact(): CatFact? {
val catFact = CatFact("This is a cat", 2)
return catFact
}
}