Do `KSerializer`s work on iOS ? I am getting an ex...
# serialization
m
Do `KSerializer`s work on iOS ? I am getting an exception in a Multiplatform project on iOS but not on Android. I have a json string that I want to parse into a list of data objects but I have to use KSerializer to manipulate the data a little bit I'm using Kotlin:2.0.0 & kotlinx-serialization-json:1.7.3 Stack trace in 🧵
Copy code
Uncaught Kotlin exception: kotlin.native.internal.FileFailedToInitializeException: There was an error during file or class initialization
at 0  Shared               0x105a4a307    ThrowFileFailedToInitializeException + 235
at 1  Shared               0x105f61bcf    CallInitGlobalPossiblyLock + 395
at 2  Shared               0x105c8e0d3    kfun:com.example.data.model.wellbeing.WellbeingAffirmationCategorySerializer#<get-$instance>#static(){}com.example.data.model.wellbeing.WellbeingAffirmationCategorySerializer + 115
at 3  Shared               0x105a42b53    kfun:kotlin.native.internal#findAssociatedObject__at__kotlin.reflect.KClass<*>(kotlin.reflect.KClass<*>){}kotlin.Any? + 211
at 4  Shared               0x105aee8f3    kfun:kotlinx.serialization.internal#constructSerializerForGivenTypeArgs__at__kotlin.reflect.KClass<0:0>(kotlin.Array<out|kotlinx.serialization.KSerializer<kotlin.Any?>>...){0§<kotlin.Any>}kotlinx.serialization.KSerializer<0:0>? + 123
at 5  Shared               0x105acde87    kfun:kotlinx.serialization#serializerOrNull__at__kotlin.reflect.KClass<0:0>(){0§<kotlin.Any>}kotlinx.serialization.KSerializer<0:0>? + 155
at 6  Shared               0x105acf07f    kfun:kotlinx.serialization.$SERIALIZERS_CACHE$lambda$0$FUNCTION_REFERENCE$0.invoke#internal + 167
at 7  Shared               0x105d12007    kfun:kotlin.Function1#invoke(1:0){}1:1-trampoline + 195
at 8  Shared               0x105aef37f    kfun:kotlinx.serialization.internal.object-2.get#internal + 55
at 9  Shared               0x105d1d053    kfun:kotlinx.serialization.internal.SerializerCache#get(kotlin.reflect.KClass<kotlin.Any>){}kotlinx.serialization.KSerializer<1:0>?-trampoline + 195
at 10 Shared               0x105acdb57    kfun:kotlinx.serialization#serializer__at__kotlinx.serialization.modules.SerializersModule(kotlin.reflect.KType){}kotlinx.serialization.KSerializer<kotlin.Any?> + 1299
at 11 Shared               0x105ace013    kfun:kotlinx.serialization#serializersForParameters__at__kotlinx.serialization.modules.SerializersModule(kotlin.collections.List<kotlin.reflect.KType>;kotlin.Boolean){}kotlin.collections.List<kotlinx.serialization.KSerializer<kotlin.Any?>>? + 275
at 12 Shared               0x105acdc43    kfun:kotlinx.serialization#serializer__at__kotlinx.serialization.modules.SerializersModule(kotlin.reflect.KType){}kotlinx.serialization.KSerializer<kotlin.Any?> + 1535
at 13 Shared               0x105c9f277    kfun:com.example.data.repository.WellbeingRepository#parseWellbeingAffirmations#suspend(kotlin.coroutines.Continuation<kotlin.Unit>){}kotlin.Any + 271
at 14 Shared               0x105d108f3    kfun:co.touchlab.skie.generated.__SkieSuspendWrappers.$Skie_Suspend__54__parseWellbeingAffirmations$lambda$54$FUNCTION_REFERENCE$54.invoke#internal + 87
at 15 Shared               0x105d1b807    kfun:kotlin.coroutines.SuspendFunction0#invoke#suspend(kotlin.coroutines.Continuation<1:0>){}kotlin.Any?-trampoline + 195
at 16 Shared               0x105c49f83    kfun:co.touchlab.skie.runtime.coroutines.suspend.Skie_SuspendHandler.$launch$lambda$1COROUTINE$0.invokeSuspend#internal + 907
at 17 Shared               0x105c4a94f    kfun:co.touchlab.skie.runtime.coroutines.suspend.Skie_SuspendHandler.$launch$lambda$1$FUNCTION_REFERENCE$0.invoke#internal + 223
at 18 Shared               0x105d13dab    kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 195
at 19 Shared               0x105a3ac7b    kfun:kotlin.coroutines.intrinsics.object-2.invokeSuspend#internal + 451
at 20 Shared               0x105a3998b    kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 187
at 21 Shared               0x105b4ffd7    kfun:kotlinx.coroutines.DispatchedTask#run(){} + 423
at 22 Shared               0x105ebe65b    objc2kotlin_virtual_kfun:kotlinx.coroutines.Runnable#run(){} + 203
at 23 Shared               0x105f6b6df    $s6Shared24SwiftCoroutineDispatcherV26executeWithoutCancellation33_6DEE54A2CB44F481938008F03DF9C669LL10dispatcheryScSySo0A31Kotlinx_coroutines_coreRunnable_pG_tYaFZyyYacfU_TY2_ + 59
at 24 libswift_Concurrency.dylib     0x2444c4c2f    _ZN5swift34runJobInEstablishedExecutorContextEPNS_3JobE + 131
at 25 libswift_Concurrency.dylib     0x2444c5e7f    _ZL17swift_job_runImplPN5swift3JobENS_17SerialExecutorRefE + 143
at 26 libdispatch.dylib          0x1068ba3d3    _dispatch_root_queue_drain + 371
at 27 libdispatch.dylib          0x1068baf7b    _dispatch_worker_thread2 + 255
at 28 libsystem_pthread.dylib       0x1052bfb37    _pthread_wqthread + 223
at 29 libsystem_pthread.dylib       0x1052be933    start_wqthread + 7
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@13780138, CoroutineDispatcherWithDelegate@1b340020]
at 0  Shared               0x105b4f11f    kfun:kotlinx.coroutines.internal#handleUncaughtCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 547
at 1  Shared               0x105b1d6ab    kfun:kotlinx.coroutines#handleCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 207
at 2  Shared               0x105b16553    kfun:kotlinx.coroutines.StandaloneCoroutine.handleJobException#internal + 43
at 3  Shared               0x105b2299b    kfun:kotlinx.coroutines.JobSupport.finalizeFinishingState#internal + 1603
at 4  Shared               0x105b2680f    kfun:kotlinx.coroutines.JobSupport.tryMakeCompleting#internal + 1371
at 5  Shared               0x105b26133    kfun:kotlinx.coroutines.JobSupport#makeCompletingOnce(kotlin.Any?){}kotlin.Any? + 243
at 6  Shared               0x105b15bd3    kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} + 127
at 7  Shared               0x105a39a77    kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 423
at 8  Shared               0x105b4ffd7    kfun:kotlinx.coroutines.DispatchedTask#run(){} + 423
... and 8 more common stack frames skipped
g
Yes KSerializer works on iOS. I can't help more without reading your implementation.
m
updating Kotlin and plugin.serialization to '2.0.21' solved the issue on iOS
still have no clue why it didn't work with 2.0.0
Thanks 😄
👍 2