UNuX
08/29/2021, 7:23 AM@Serializable
data class EntryRecord(
val id: Int?,
@Contextual val creationDate: Date?,
val contractType: String,
val contractNumber: String,
val pricePrepaid: Int,
var pricePrepaidConfirmed: Boolean,
val priceTotal: Int,
var priceTotalConfirmed: Boolean,
val additionalInfo: String?
)
Is serialized to this string:
"{"_id":null,"_creationDate":null,"_contractType":"Test","_contractNumber":"Test","_pricePrepaid":20099,"_pricePrepaidConfirmed":false,"_priceTotal":400095,"_priceTotalConfirmed":false,"_additionalInfo":""}"
Why is kotlin adding _
in front of every field name? How do I get rid of this?Robert Jaros
08/29/2021, 7:43 AMUNuX
08/29/2021, 8:01 AMfun addRecord(record: EntryRecord): Promise<dynamic> {
return RestClient().requestDynamic("/api/v1/records") {
method = <http://HttpMethod.POST|HttpMethod.POST>
data = record
}
}
Is there a better way?Robert Jaros
08/29/2021, 8:08 AMRestClient().requestDynamic("/api/v1/records", data) {
method = <http://HttpMethod.POST|HttpMethod.POST>
}
Robert Jaros
08/29/2021, 8:08 AMRobert Jaros
08/29/2021, 8:11 AMRestRequestConfig
(like in your example) it will be passed directly to fetch API if you won't provide a serializer as well.Robert Jaros
08/29/2021, 8:12 AMinline fun <reified V : Any> RestClient.requestDynamic(
url: String,
data: V,
crossinline block: RestRequestConfig<dynamic, V>.() -> Unit = {}
): Promise<RestResponse<dynamic>> {
return receive<dynamic, V>(url) {
block.invoke(this)
this.data = data
this.serializer = serializer()
}
}
UNuX
08/29/2021, 10:28 AM