Chetan Tuteja
05/12/2021, 7:02 AMwbertan
05/12/2021, 7:56 AM@Serializable
and properties annotated with @SerialName
. So far so good.Chetan Tuteja
05/12/2021, 7:59 AMwbertan
05/12/2021, 8:07 AMGET
and PATCH
also having a Path
, but we use simple String
as a parameter, so we don’t have that issue.
For us here is fine, as it seems simple enough and on our architecture APIs are only used in Repository classes, so we didn’t feel the need to make it strict in the parameters to be a class type too.Chetan Tuteja
05/12/2021, 8:10 AMwbertan
05/12/2021, 8:28 AMChetan Tuteja
05/12/2021, 8:36 AMChetan Tuteja
05/12/2021, 8:41 AMprivate val contentType = "application/json".toMediaType()
private val jsonConfig = JsonConfiguration.Stable.copy(prettyPrint = true, ignoreUnknownKeys = true)
private val json = Json(jsonConfig)
private val userApi = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(json.asConverterFactory(contentType))
.build()
.create(UserApi::class.java)
wbertan
05/12/2021, 8:59 AMval contentType = "application/json".toMediaType()
val jsonConverter = Json {
ignoreUnknownKeys = true
}.asConverterFactory(contentType)
return Retrofit.Builder()
.baseUrl(urlProvider.url)
.addConverterFactory(jsonConverter)
wbertan
05/12/2021, 9:00 AM@Serializable
data class SomeDto(
@SerialName("fieldName") val fieldName: Boolean? = false
)