saket
02/21/2020, 7:58 PMkevin.cianfarini
02/21/2020, 8:06 PMkevin.cianfarini
02/21/2020, 8:07 PMThomas
02/22/2020, 5:44 PMalec
02/22/2020, 9:47 PMalec
02/22/2020, 9:48 PMThomas
02/22/2020, 11:38 PMbasePath
which looks like the way to go. Appreciate your help!Thomas
02/27/2020, 9:06 PMjw
02/27/2020, 9:40 PMThomas
02/27/2020, 9:43 PMjw
02/27/2020, 9:47 PMalec
02/27/2020, 11:39 PMalec
02/27/2020, 11:40 PMdave08
03/02/2020, 2:21 PM@JsonClass(generateAdapter = true)
data class ApplicationGroup(
val id: Int,
val header: String,
val subHeader: String = ""
)
but I'm getting this error:
java.lang.NoSuchMethodException: parameter type is null
at java.lang.Class.getConstructor(Class.java:526)
at java.lang.Class.getDeclaredConstructor(Class.java:510)
at com.....ApplicationGroupJsonAdapter.fromJson(ApplicationGroupJsonAdapter.kt:62)
at com.....ApplicationGroupJsonAdapter.fromJson(ApplicationGroupJsonAdapter.kt:19)
at com.squareup.moshi.u.b.fromJson(NullSafeJsonAdapter.java:40)
at com.squareup.moshi.d.fromJson(CollectionJsonAdapter.java:76)
at com.squareup.moshi.d$b.fromJson(CollectionJsonAdapter.java:53)
at com.squareup.moshi.u.b.fromJson(NullSafeJsonAdapter.java:40)
at com.squareup.moshi.f$c.fromJson(JsonAdapter.java:197)
what could be causing this?Zac Sweers
03/02/2020, 7:03 PMTolriq
03/02/2020, 7:27 PMZac Sweers
03/02/2020, 7:28 PMmyanmarking
03/04/2020, 12:20 PMmyanmarking
03/04/2020, 12:20 PMmyanmarking
03/04/2020, 12:20 PMmyanmarking
03/04/2020, 12:21 PMsuspend fun someApiCall(): Unit
jw
03/04/2020, 12:49 PMjw
03/04/2020, 12:49 PMmyanmarking
03/04/2020, 1:34 PMjw
03/04/2020, 1:35 PMColton Idle
03/04/2020, 5:15 PMjw
03/04/2020, 5:21 PMColton Idle
03/04/2020, 6:03 PMclass DefaultIfNullFactory : JsonAdapter.Factory {
override fun create(type: Type, annotations: MutableSet<out Annotation>,
moshi: Moshi): JsonAdapter<*>? {
val delegate = moshi.nextAdapter<Any>(this, type, annotations)
return object : JsonAdapter<Any>() {
override fun fromJson(reader: JsonReader): Any? {
val blob1 = reader.readJsonValue()
try {
val blob = blob1 as Map<String, Any?>
val noNulls = blob.filterValues { it != null }
return delegate.fromJsonValue(noNulls)
} catch (e: Exception) {
return delegate.fromJsonValue(blob1)
}
}
override fun toJson(writer: JsonWriter, value: Any?) {
return delegate.toJson(writer, value)
}
}
}
}
Which actually seems to work great (not a fan of the try statement), but it still has that interesting issue where while it filters out nulls, it turns Json numbers in Java doubles, and so when 1583674200000
comes in over the wire, my data class has timestamp: String
and so the end result is "1.5836742E12" instead of "1583674200000".
So it "appears" that it doesn't work. Unless there's some other way to filter nulls besides Zacs advice of reading jsonValue as map, filter nulls, pass it along the chain.jw
03/04/2020, 6:06 PMjw
03/04/2020, 6:06 PM