I’m building an API using Quarkus + Kotlin for learning purpose and i’m having a problem **deserializing **a response to my DTO classes. Apparently data is not being copied to DTO properties, and the DTO is returning all blank, just as created on the default constructors.
Actually the DTO classes are using two Lombok annotations, @NoArgs and @AllArgs for constructors, but, i read on some forum that Lombok needs some adaptations to work with Kotlin. Then, i tried switch DTOs to Java classes and it worked!
Theres anything on Kotlin needed to deserealize responses to classes correctly?
The API is consuming another API of Currency Quotation data, using Rest Client, that returns an response as the example below:
{
"USDBRL": {
"code": "USD",
"codein": "BRL",
"name": "Dólar Americano/Real Brasileiro",
"high": "5.1684",
"low": "5.1603",
"varBid": "-0.0004",
"pctChange": "-0.01",
"bid": "5.1602",
"ask": "5.1612",
"timestamp": "1716935404",
"create_date": "2024-05-28 19:30:04"
}
}
And thats the code of the DTOs **Kotlin **classes:
@NoArgsConstructor
@AllArgsConstructor
class CurrencyPriceDTO (
USDBRL: USDBRL
){
constructor(): this(USDBRL())
val USDBRL = USDBRL
}
@NoArgsConstructor
@AllArgsConstructor
class USDBRL (
code: String,
codein: String,
name: String,
high: String,
low: String,
varBid: String,
pctChange: String,
bid: String,
ask: String,
timestamp: String,
create_date: String
){
constructor(): this(
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
)
val code = code
val codein = codein
val name = name
val high = high
val low = low
val varBid = varBid
val pctChange = pctChange
val bid = bid
val ask = ask
val timestamp = timestamp
val create_date = create_date
}
When a read the information about the incompatibillity of Lombok with Kotlin, i also tried to implement those default constructors. But, the problem still happen.
Israel Alves is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.