Zac Sweers
07/15/2022, 12:58 AMimport com.squareup.moshi.adapter
Colton Idle
07/15/2022, 1:00 AM@OptIn(ExperimentalStdlibApi::class)
to my method. 🙏Javier
07/22/2022, 10:54 AMMockWebServer
?galex
07/24/2022, 4:26 PMokhttp
😊
We're using okhttp
with Retrofit
and Apollo
, and I'd like to get the full http request right before it is really being executed.
I can get the Call.request()
to get the request object but this one doesn't contain the headers we're adding through interceptors for example...
Is there any extension to get the real request? Or am I correct to assume I can't use interceptors if I want to achieve this?jw
07/24/2022, 4:33 PMgalex
07/24/2022, 4:54 PMjw
07/24/2022, 5:01 PMitnoles
07/24/2022, 11:54 PM<https://www.apollographql.com/docs/kotlin/advanced/interceptors-http#reusing-okhttp-interceptors-on-jvm-only-projects> this could help or not
xxfast
07/25/2022, 1:49 AM<http://JdbcSqliteDriver.IN|JdbcSqliteDriver.IN>_MEMORY
, but I'm looking for something more permanentjw
07/25/2022, 2:44 AMjdbc:sqlite:/path/to/file.db
for a persisted sqlite databaseMikeH
07/26/2022, 3:05 PMsaket
07/26/2022, 3:25 PMLukasz Kalnik
07/28/2022, 3:49 PMtrigger
in my JSON. Then, for trigger
type SENSOR
I can have (nested) different types of condition
(examples see in thread 🧵:jw
07/28/2022, 3:52 PMreadJsonValue()
that will give you a Map
(for a JSON object) which you can query to determine the "shape" of the object. Then, you can delegate to the correct adapter which can parse that specific shape. So for your root object you would delegate to an adapter for a Time
or Sensor
object. Now the problem is fractal so you just repeat yourself. You register a custom adapter for Sensor
which does the same thing (reads the json a "value" and inspects it) to create either an AlwaysCondition
or a ThresholdCondition
.jw
07/28/2022, 3:54 PMjw
07/28/2022, 3:56 PMTrigger
and then once for Condition
.Lukasz Kalnik
07/28/2022, 3:59 PMTrigger
and Condition
types with @ToJson
and @FromJson
function implementations. I then registered them both with Moshi using add()
, but then the internal Condition
object was serialized as plain string (with all the JSON symbols like {}
etc. escaped with \
).Lukasz Kalnik
07/28/2022, 4:00 PMjw
07/28/2022, 4:02 PMJsonWriter
as a parameter which gives you access to write raw JSON (or to pass the JsonWriter
along to a delegate adapter so it can). Perhaps you could look at the implementation of the polymorphic adapter to get some ideas. There's also some examples in the repository for custom adapter things.Lukasz Kalnik
07/28/2022, 4:03 PMLukasz Kalnik
07/29/2022, 8:57 AM@ToJson
implementation: I was using toJson()
instead of toJsonValue()
. That's why the serialized JSON was escaped like a plain string. It didn't have anything to do with nesting.
But I will switch to a polymorphic adapter factory anyway, because then I won't have to implement from/to JSON functions myself and won't be able to make these kind of errors.yshrsmz
08/02/2022, 9:46 AMLukasz Kalnik
08/02/2022, 1:39 PMMoshiConverterFactory
for my API calls, however it doesn't support sealed classes containing `object`s.
I'm trying to generate adapters for the sealed class hierarchy using moshi-sealed
, but I still get the error object Always cannot be serialized
. Here the hierarchy:
@Keep
@JsonClass(generateAdapter = true, generator = "sealed:type")
sealed class TriggerCondition(val type: String) : Serializable {
@Keep
@TypeLabel("ALWAYS")
object Always : TriggerCondition("ALWAYS")
@Keep
@TypeLabel("NIGHT")
object Night : TriggerCondition("NIGHT")
@Keep
@TypeLabel("LIGHT_SENSOR")
@JsonClass(generateAdapter = true)
data class LightSensor(
val sensorInfo: SensorInfo,
) : TriggerCondition("LIGHT_SENSOR")
}
Emirhan Emmez
08/02/2022, 11:06 AMclass TokenInterceptor @Inject constructor(
private val preferencesRepository: PreferencesRepository,
private val cognitoRepository: CognitoRepository
) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
return runBlocking {
val request = chain.request().newBuilder().build()
if (preferencesRepository.isTokenExpired()) {
cognitoRepository.login(
number = null,
password = null,
refreshToken = preferencesRepository.getRefreshToken(),
loginType = CognitoRepository.LoginType.RefreshToken
).collect()
}
chain.proceed(request)
}
}
}
Stylianos Gakis
08/04/2022, 9:55 AMfun <T : SomeType> foo(param: Bar<T>): Unit {
asdf(myParam)
}
Is there some part of the docs which I am missing? If so I’d really appreciate any pointers.KamilH
08/05/2022, 5:43 PMjw
08/05/2022, 5:43 PMjw
08/05/2022, 5:44 PMKamilH
08/05/2022, 6:31 PMKamilH
08/05/2022, 6:31 PM