Akbar
12/31/2021, 2:16 PMJeremiah Zucker
01/03/2022, 8:25 PMclass SomeSerializer : KSerializer<SomeClass> {
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("SomeClass") {
element<Boolean>("flag")
element("nested", SomeSerializer().descriptor, isOptional = true)
}
// ...
}
This leads to a stack overflow since the init
of SomeSerializer
creates the descriptor
which then tries to new up another SomeSerializer
. That makes sense to me, but I wasn’t sure what the intended way of accomplishing something like this is. I know it’s possible if using one of the plugin generated serializers. Does this mean I might potentially need to implement SerialDescriptor
myself or is this something that’s already solved for and I’m just not seeing the path forward?Jan
01/04/2022, 12:08 AMfunction handleData(data: Record<string, unknown>) {
const bar: Record<string,unknown> = {
foo: "hi",
props: {...this.otherData, ...data}
}
return bar
}
This should end up as
{
foo: "hi",
props: {
uno: 1
dos: "two"
}
}
Eugen Martynov
01/04/2022, 11:35 AMsindrenm
01/04/2022, 5:30 PM@JsonClassDiscriminator
makes class discriminators more customizable)? Sample code in thread.jeff
01/04/2022, 5:36 PMrocketraman
01/06/2022, 7:47 PM_type
instead of type
as the discriminator. Doing @SerialName("_type") val type: String
doesn't seem to work. A JSON content-based polymorphic deserialization seems like overkill for this. Is there some annotations that will work short of that?andylamax
01/07/2022, 12:28 AM@Serializable(with = SignedIn.Companion::class)
interface SignedIn : Session {
@Serializer(forClass = SignedIn::class)
companion object : KSerializer<SignedIn> {
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("session.signedin")
override fun deserialize(decoder: Decoder): SignedIn {
TODO("Not yet implemented")
}
override fun serialize(encoder: Encoder, value: SignedIn) {
TODO()
}
}
}
And my test are as follows
val session : SignedIn = getSession()
println(Json.encodeToString(session)) // fails with: Serializer for class 'SignedIn' is not found.
println(Json.encodeToString(SignedIn,session)) // passes
println(Json.encodeToString(SignedIn.serializer(),session)) // won't compile
Why can't the compiler find the custom serializer??Jason5lee
01/08/2022, 1:01 PMRahul Rawat
01/09/2022, 6:10 PMjava.lang.RuntimeException: Unable to instantiate application com.rawat.address.AddressApp: java.lang.TypeNotPresentException: Type kotlinx.serialization.json.Json not present
at android.app.LoadedApk.makeApplication(LoadedApk.java:1244)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6683)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.TypeNotPresentException: Type kotlinx.serialization.json.Json not present
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:69)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:77)
at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:76)
at libcore.reflect.Types.getType(Types.java:56)
at java.lang.Class.getGenericSuperclass(Class.java:878)
at org.kodein.type.TypeReference.<init>(typeTokensJVM.kt:65)
at com.library.address.di.KodeinKt$commonModule$$inlined$bindSingleton$default$1.<init>(typeTokensJVM.kt:83)
at com.library.address.di.KodeinKt.commonModule(Kodein.kt:79)
at com.library.address.di.KodeinKt.access$commonModule(Kodein.kt:1)
at com.library.address.di.KodeinKt$initKodein$container$1.invoke(Kodein.kt:26)
at com.library.address.di.KodeinKt$initKodein$container$1.invoke(Kodein.kt:23)
at org.kodein.di.internal.DIImpl$Companion.newBuilder(DIImpl.kt:21)
at org.kodein.di.internal.DIImpl$Companion.access$newBuilder(DIImpl.kt:20)
at org.kodein.di.internal.DIImpl.<init>(DIImpl.kt:18)
at org.kodein.di.DI$Companion.invoke(DI.kt:460)
at org.kodein.di.DI$Companion.invoke$default(DI.kt:460)
at com.library.address.di.KodeinKt.initKodein(Kodein.kt:23)
at com.library.address.di.KodeinKt.initKodein$default(Kodein.kt:22)
at com.rawat.address.AddressApp.<init>(AddressApp.kt:8)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
at android.app.Instrumentation.newApplication(Instrumentation.java:1158)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1236)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6683)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.ClassNotFoundException: kotlinx.serialization.json.Json
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:67)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:77)
at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:76)
at libcore.reflect.Types.getType(Types.java:56)
at java.lang.Class.getGenericSuperclass(Class.java:878)
at org.kodein.type.TypeReference.<init>(typeTokensJVM.kt:65)
at com.library.address.di.KodeinKt$commonModule$$inlined$bindSingleton$default$1.<init>(typeTokensJVM.kt:83)
at com.library.address.di.KodeinKt.commonModule(Kodein.kt:79)
at com.library.address.di.KodeinKt.access$commonModule(Kodein.kt:1)
at com.library.address.di.KodeinKt$initKodein$container$1.invoke(Kodein.kt:26)
at com.library.address.di.KodeinKt$initKodein$container$1.invoke(Kodein.kt:23)
at org.kodein.di.internal.DIImpl$Companion.newBuilder(DIImpl.kt:21)
at org.kodein.di.internal.DIImpl$Companion.access$newBuilder(DIImpl.kt:20)
at org.kodein.di.internal.DIImpl.<init>(DIImpl.kt:18)
at org.kodein.di.DI$Companion.invoke(DI.kt:460)
at org.kodein.di.DI$Companion.invoke$default(DI.kt:460)
at com.library.address.di.KodeinKt.initKodein(Kodein.kt:23)
at com.library.address.di.KodeinKt.initKodein$default(Kodein.kt:22)
at com.rawat.address.AddressApp.<init>(AddressApp.kt:8)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
at android.app.Instrumentation.newApplication(Instrumentation.java:1158)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1236)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6683)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlinx.serialization.json.Json" on path: DexPathList[[dex file "/data/data/com.rawat.address/code_cache/.overlay/base.apk/classes7.dex", zip file "/data/app/~~U3m2k-_-ig7S7cGbCNubiA==/com.rawat.address-AHUnIhfVwegLlNWqeSa9yQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~U3m2k-_-ig7S7cGbCNubiA==/com.rawat.address-AHUnIhfVwegLlNWqeSa9yQ==/lib/x86, /system/lib, /system_ext/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:67)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:77)
at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:76)
at libcore.reflect.Types.getType(Types.java:56)
at java.lang.Class.getGenericSuperclass(Class.java:878)
at org.kodein.type.TypeReference.<init>(typeTokensJVM.kt:65)
at com.library.address.di.KodeinKt$commonModule$$inlined$bindSingleton$default$1.<init>(typeTokensJVM.kt:83)
at com.library.address.di.KodeinKt.commonModule(Kodein.kt:79)
at com.library.address.di.KodeinKt.access$commonModule(Kodein.kt:1)
at com.library.address.di.KodeinKt$initKodein$container$1.invoke(Kodein.kt:26)
at com.library.address.di.KodeinKt$initKodein$container$1.invoke(Kodein.kt:23)
at org.kodein.di.internal.DIImpl$Companion.newBuilder(DIImpl.kt:21)
at org.kodein.di.internal.DIImpl$Companion.access$newBuilder(DIImpl.kt:20)
at org.kodein.di.internal.DIImpl.<init>(DIImpl.kt:18)
at org.kodein.di.DI$Companion.invoke(DI.kt:460)
at org.kodein.di.DI$Companion.invoke$default(DI.kt:460)
at com.library.address.di.KodeinKt.initKodein(Kodein.kt:23)
at com.library.address.di.KodeinKt.initKodein$default(Kodein.kt:22)
at com.rawat.address.AddressApp.<init>(AddressApp.kt:8)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
at android.app.Instrumentation.newApplication(Instrumentation.java:1158)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1236)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6683)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Can anyone help?andylamax
01/10/2022, 12:25 PM> Task compileKotlinJs FAILED
e: Could not find "org.jetbrains.kotlinx:kotlinx-serialization-core" in [/home/andylamax/.local/share/kotlin/daemon]
e: java.lang.IllegalStateException: Could not find "org.jetbrains.kotlinx:kotlinx-serialization-core" in [/home/andylamax/.local/share/kotlin/daemon]
It should be known that this is a multiplatform project and task compileKotlinJvm completes successfully. Anyone experienced this?? how do I solve it??
Full error log in threadFlorian Magin
01/11/2022, 3:07 PMInteger -> User
when I instantiate the JSON deserializer. Is there such a functionality already available?Eugen Martynov
01/13/2022, 4:21 PM@Serializable
@Contextual
abstract class BaseCreateProfileData {...}
Nikky
01/14/2022, 11:38 AM"{"type": "A", ...}"
into a PolymorphicType.A.serializer()
it fails with a Unexpected JSON token at offset 11: Encountered an unknown key 'type'.
is there a way to skip that.. while also not adding type
as a property to the class (because that creates other issue)
or using ignoreUnknownKeys = true
because there could be other.. issues ?
oone way i found was to use
val a = Json.decodeFromString(PolymorphicType.serializer(), jsonString) as PolymorphicType.A
but that means that there is no way to use this.. except for encoding and decoding using the polymorphic types.. or you wil lose the type
propertiesEugen Martynov
01/14/2022, 3:42 PMJsonTransformingSerializer
to remove discriminator?spierce7
01/15/2022, 4:13 AMrocketraman
01/19/2022, 3:57 PMandrew
01/19/2022, 6:36 PMv79
01/25/2022, 9:17 PM2022-01-25T21:03:42.507+0000 [DEBUG] [org.gradle.execution.plan.Node] Checking if all dependencies are complete for :jsProductionExecutableCompileSync
2022-01-25T21:03:42.507+0000 [DEBUG] [org.gradle.execution.plan.Node] All dependencies are complete for :jsProductionExecutableCompileSync
2022-01-25T21:03:42.507+0000 [DEBUG] [org.gradle.execution.plan.TaskNode] Checking if all must successors are complete for :jsProductionExecutableCompileSync
java.util.NoSuchElementException: Collection contains no element matching the predicate.
at org.jetbrains.kotlinx.serialization.compiler.backend.ir.IrBuilderExtension$DefaultImpls.createLazyProperty(GeneratorHelpers.kt:1401)
at org.jetbrains.kotlinx.serialization.compiler.backend.ir.SerializableCompanionIrGenerator.createLazyProperty(SerializableCompanionIrGenerator.kt:35)
at org.jetbrains.kotlinx.serialization.compiler.backend.ir.SerializableCompanionIrGenerator.generateLazySerializerGetter(SerializableCompanionIrGenerator.kt:114)
at org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializableCompanionCodegen.generate(SerializableCompanionCodegen.kt:37)
at org.jetbrains.kotlinx.serialization.compiler.backend.ir.SerializableCompanionIrGenerator$Companion.generate(SerializableCompanionIrGenerator.kt:50)
at org.jetbrains.kotlinx.serialization.compiler.extensions.SerializerClassLowering.lower(SerializationLoweringExtension.kt:60)
...
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1802)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
I have code which runs and compiles fine on the JVM, but fails when compiling to Javascript. The error logs don't tell me where in my code it's failing. If it helps, my data model to be serialized has a sealed
class with a number of children, each of which implement different interfaces. None of them use by lazy
.iamthevoid
01/26/2022, 3:21 PMGeorge
01/27/2022, 3:57 PMJavier
01/30/2022, 2:16 AM@Serializable(with = CustomSealedClassSerializer::class)
. But I want to remove the dependency on json
this sealed class in that Gradle module so I tried to use a SerializerModule
Json {
serializersModule = SerializersModule {
contextual(CustomSealedClassSerializer::class) { args -> CustomSealedClassSerializer(args[0], args[1] }
}
...
}
This is working perfectly with local strings, but with Ktor 2.0.0-alpha-1
and doing a request, it is not working, and debugging I am getting that args
list is empty.
Is there any workaround?Guilherme Delgado
01/31/2022, 5:47 PMMap<String, String>
json response from github’s API into a List<Object>
but I’m failing to do so, more in the threaddave08
02/02/2022, 12:36 PM{"a": "a", "b":true, "c":1, "d": 10000000000000000000}
(if I want it as Map<String, Any>
), and would it differentiate between Int
Long
Float
and Double
? Or does it just put all numbers in one of those (In Moshi, they just put them all in Doubles... https://github.com/square/moshi/issues/1144)? Do I need to manually serialize all this or is there an easy way to do this?Kuba Petržílka
02/02/2022, 3:04 PMsealed interface SystemXsId {
@Serializable
@JvmInline
value class Known(val value: NonEmptyString) : SystemXsId
@Serializable
object Unknown : SystemXsId
}
to be serialized either as:
• the value of NonEmptyString (which is already serializable and it works) - in case it is Known
• null in case it is Unknown
I probably have to specify an explicit serializer for the sealed interface, but how would it look like?Rohan Maity
02/03/2022, 4:05 PMSerializable
of java ?
why I am asking this question, actually we need to store the some serialized data in local/Room DB
With Java's Serializable, problem is if we make any changes to the class implementing Serializable,. Its serialVersionUID
gets changed, which causes the problem in deserializingLost Illusion
02/05/2022, 11:04 PM{
"type": 1,
"realm": "dev"
}
would actually be serialized as
[1, "dev"]
and I'm not too sure how to go about this. I was going to go with a message hierarchy and then delegate to the specific serializer based off the type, which I've successfully done before with the first JSON example. Though, I'm not sure how to do that with the second example, nor how to even (de)serialize the second example into a class that would look like this.
data class Foo(val type: Int, val realm: String)
It'd be nice to know if this is even possible, since I'm completely stumped on how to create a proper descriptor for the second situation.
Thanks.Dariusz Kuc
02/06/2022, 8:39 PMkotlinx-serialization
? I'm trying to test out my auto-generated code but since serialization build plugin wasn't run, my compilation is failing as the serialization generated code is not available (e.g. <foo>.serializer()
on serializable objects). Any ideas/suggestions?Ayfri
02/06/2022, 9:54 PM@Serializable
enum class Environment {
BOTH,
CLIENT,
SERVER;
}
And I want the BOTH
value to be serialized to *
alightgoesout
02/09/2022, 1:00 PMId<T>
where T
is not actually used for serialization/deserialization. I have written a custom serializer for it that I have declared on the class (@Serializable(with = IdSerializer::class) Id<T> {…}
). The custom serializer is declared as KSerializer<Id<*>>
and it does not take any parameter.
So far it works well, except that if I used it with a parameter that is not serializable (e.g., Id<User>
), the compiler complains and I have to add a @Contextual
annotation to the parameter.
Is there a way to specify that the parameter is ignored? (for instance, using an annotation)alightgoesout
02/09/2022, 1:00 PMId<T>
where T
is not actually used for serialization/deserialization. I have written a custom serializer for it that I have declared on the class (@Serializable(with = IdSerializer::class) Id<T> {…}
). The custom serializer is declared as KSerializer<Id<*>>
and it does not take any parameter.
So far it works well, except that if I used it with a parameter that is not serializable (e.g., Id<User>
), the compiler complains and I have to add a @Contextual
annotation to the parameter.
Is there a way to specify that the parameter is ignored? (for instance, using an annotation)Dominaezzz
02/09/2022, 6:33 PMalightgoesout
02/10/2022, 9:51 AM