fun createJson() = Json { isLenient = true; ignoreUnknownKeys = true; prettyPrint = true;}
fun createHttpClient(httpClientEngine: HttpClientEngine, json: Json, enableNetworkLogs: Boolean) = HttpClient(httpClientEngine) {
install(ContentNegotiation) {
json(json)
}
if (enableNetworkLogs) {
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.ALL
}
}
}
@Serializable
data class ResourceResponse (
@SerialName("Id" ) var Id : String? = null,
@SerialName("Titulo" ) var Titulo : String? = null,
@SerialName("Descripcion" ) var Descripcion : String? = null,
@SerialName("TipoRecurso" ) var TipoRecurso : Int? = null,
@SerialName("RecursoData" ) var RecursoData : String? = null,
@SerialName("UrlRecurso" ) var UrlRecurso : String? = null,
@SerialName("FileType" ) var FileType : String? = null,
@SerialName("FileName" ) var FileName : String? = null,
@SerialName("File" ) var File : String? = null,
@SerialName("DataSrc" ) var DataSrc : String? = null,
@SerialName("IdYoutube" ) var IdYoutube : String? = null,
@SerialName("IdTrabajadores") var IdTrabajadores : ArrayList<String>? = null,
)
My backend team add new filed to json "IdCreador" is a String.
I don´t need this field, therefore, I dont´add this field to my ResourceResponse object,
I had define ignoreUnknownKeys = true but I get the following error
kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 278: Encountered an unknown key 'IdCreador' at path: $[0].IdTrabajadores Use 'ignoreUnknownKeys = true' in 'Json {}' builder to ignore unknown keys.
JSON input: .....":null,"IdTrabajadores":null,"IdCreador":null
val ktorVersion = "2.3.2"
//Ktor
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("io.ktor:ktor-client-auth:$ktorVersion")
install(ContentNegotiation) {
val json = Json {
ignoreUnknownKeys = true
}
json(json)
}
But the result is the same.... JsonDecodingException