jw
01/30/2023, 12:20 AMjw
01/30/2023, 12:21 AMColton Idle
01/30/2023, 12:22 AMColton Idle
01/30/2023, 1:00 AM@Throws(IOException::class)
fun writeStringToFile(path: Path, myMessage: String) {
FileSystem.SYSTEM.createDirectories(path)
FileSystem.SYSTEM.write(path) {
writeUtf8(myMessage)
}
}
Calling code
writeStringToFile("mydir/myMessage.json".toPath(), "hello, moto")
Keep getting java.io.IOException: failed to create directory: mydir
edit: maybe cuz im on an emu 🤔Colton Idle
01/30/2023, 1:28 AMOscar Fuentes
01/31/2023, 7:50 PMdimsuz
02/01/2023, 11:30 AMmattinger
02/02/2023, 9:44 PMPhilip Dukhov
02/03/2023, 4:11 AMUser
with many fields and class CurrentUser
which should have all the fields from User
plus some other keys.
That's how I'm receiving it from the server: CurrentUser
just has some additional fields that should be presented in json.
e.g. user is {"name":"Phil", "avatarUrl":"<https://some.url>"}
and current user is {"name":"Phil", "avatarUrl":"<https://some.url>", "token":"lorem ipsum"}
I could've inherit, but it'd require me to repeat all of user fields.
I solved it by making a custom adapter factory that reads extra properties from json and than pass it to UserAdapter
to fill it. But it takes a lot of boilerplate code, maybe there's some built in solution for such case? I'd like to add some annotation to user
property so codegen would write something similar for me. Or is there a way to build a general factory for such cases?
data class CurrentUser(
val token: String,
val user: User,
) {
companion object {
private const val tokenKey = "token"
val adapterFactory = JsonAdapter.Factory { type, _, moshi ->
if (type != CurrentUser::class.java) {
return@Factory null
}
val userJsonAdapter = moshi.adapter(User::class.java)
object : JsonAdapter<CurrentUser>() {
override fun fromJson(reader: JsonReader): CurrentUser? {
val jsonValue = reader.readJsonValue()
?: return null
if (jsonValue !is Map<*, *>) {
throw IllegalStateException("${this@Companion} readJsonValue is not map: $jsonValue")
}
return CurrentUser(
token = jsonValue[tokenKey] as? String
?: throw IllegalStateException("$tokenKey not found in $jsonValue"),
user = userJsonAdapter.fromJsonValue(jsonValue)
?: throw IllegalStateException("Failed to parse user from $jsonValue"),
)
}
override fun toJson(writer: JsonWriter, value: CurrentUser?) {
value?.user
?.let(userJsonAdapter::toJsonValue)
?.asMap()
?.plus(mapOf(tokenKey to value.token))
?.let(writer::jsonValue)
}
}
}
}
}
jean
02/05/2023, 11:30 AMval error = TypeVariableName(
name = "Error",
bounds = listOf(ClassName(Throwable::class.java.packageName, Throwable::class.java.simpleName)),
)
but kotlin poet automatically add import java.lang.Throwable
. How can I make it use kotlin.Throwable
instead of the java one? I tried to specify it in the ClassName
declaration but it did’t work.jw
02/05/2023, 11:45 AMClassName("kotlin", "Throwable")
ephemient
02/05/2023, 12:16 PMkotlin.Throwable
too,
import com.squareup.kotlinpoet.asClassName
Throwable::class.asClassName()
Michal Harakal
02/05/2023, 7:46 PMAwtUiDispatcher
in the following discussion https://kotlinlang.slack.com/archives/C5HT9AL7Q/p1674874708031219?thread_ts=1674874313.350269&cid=C5HT9AL7Q
Do you have any hint on existing implementation? I din’t find anything, neither in molecule nor in redwood. Even a hint how to use it directly with Immediate
would helpful. Thank you.Landry Norris
02/07/2023, 7:15 PMjw
02/07/2023, 7:16 PMjw
02/07/2023, 7:17 PMLandry Norris
02/07/2023, 7:18 PMjw
02/07/2023, 7:19 PMjw
02/07/2023, 7:20 PMLandry Norris
02/07/2023, 7:22 PMjw
02/07/2023, 7:26 PMxxfast
02/08/2023, 12:43 AMcompose plugin produces incorrect IR which serialization plugin is unable to work withFrom release notes it looks like molecule uses compose compiler plugin 1.4.0 (stable), which have fixed by this but seems to be still reproducible. Anyone else running into this problem?
Trevor Stone
02/10/2023, 8:15 PMsaket
02/10/2023, 8:24 PMsaket
02/10/2023, 8:24 PMlaunchMolecule
or something?saket
02/10/2023, 8:24 PMViewModel
because you want to retain your presenters across activity recreations?Trevor Stone
02/10/2023, 8:54 PMTrevor Stone
02/10/2023, 8:54 PMkevin.cianfarini
02/10/2023, 10:13 PMViewModel
with DI/Compose is bad. The only thing keeping many of the architecture libraries going is momentum.kevin.cianfarini
02/10/2023, 10:14 PM