You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In object additonal_data value can be null or String, but sometimes I receive an array from backend. What is the correct approach to ignore wrong type of data and paste/set this property to null.
Code I currently have related to issue:
class IgnoreDataAdapter<T> private constructor(
private val delegate: JsonAdapter<T>
) : JsonAdapter<T>() {
@FromJson
override fun fromJson(reader: JsonReader): T? {
reader.setFailOnUnknown(false)
val peeked = reader.peekJson()
val result: T? = try {
delegate.fromJson(peeked)
} catch (e: JsonDataException) {
null
} finally {
peeked.close()
}
reader.skipValue()
return result
}
@ToJson
override fun toJson(writer: JsonWriter, value: T?) {
delegate.toJson(writer, value)
}
}
But in this case Object. I am interested in specific property to be set to null (when data are garbage). How could I achieve that (without parsing all property by property)?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I do have a json:
In object additonal_data value can be null or String, but sometimes I receive an array from backend. What is the correct approach to ignore wrong type of data and paste/set this property to null.
Code I currently have related to issue:
But in this case Object. I am interested in specific property to be set to null (when data are garbage). How could I achieve that (without parsing all property by property)?
Beta Was this translation helpful? Give feedback.
All reactions