https://kotlinlang.org logo
#serialization
Title
# serialization
k

Ken

10/30/2018, 6:00 PM
Sorry if this isn't the correct channel for this question. I attempted to upgrade to Kotlin 1.3. I had been using Kotlinx Serialization 0.6.2 and its associated plugins for Maven and Intellij. When I attempted to build, the compiler errors out on the @Serializable annotation with: java.lang.IllegalStateException: Backend Internal error: Exception during code generation Cause: org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl.initialize(Lorg/jetbrains/kotlin/types/KotlinType;Lorg/jetbrains/kotlin/descriptors/ReceiverParameterDescriptor;Ljava/util/List;Ljava/util/List;Lorg/jetbrains/kotlin/types/KotlinType;Lorg/jetbrains/kotlin/descriptors/Modality;Lorg/jetbrains/kotlin/descriptors/Visibility;)Lorg/jetbrains/kotlin/descriptors/impl/SimpleFunctionDescriptorImpl; I removed the Kotlinx plugin from Maven pom, and rebuilt the compile succeeds but my unit test fail with the exception: kotlinx.serialization.SerializationException: Can't locate default serializer for class <myclass> I then tried by upgrading to Kotlinx Serializer 0.9.0, but the signature fo kotlinx.serialization.json.JSON.stringify and parse have change to require a Serializer as its first argument and the @ImplicitReflectionSerializer annotations for all clients - this change doesn't seem to be documented anywhere and for me has major implications. I have to ask all my clients to add @ImplicitReflectionSerializer before using my library methods. Is there a better way to handle this change. It seems like a "breaking" change that should have been called out and documented. Here is my code with the issue, wondering if Generics is contributing to the issue: inline fun <reified T: Any> parseToClass(jsonResponse: String): T { try { return JSON.nonstrict.parse<T>(jsonResponse) } catch(ex: Exception) { Logger.error("Failed to parse JSON to class ${T::class.simpleName}", ex) throw ex } }
s

sandwwraith

10/31/2018, 2:37 AM
You can use non-propagating annotation
@UseExperimental(kotlinx.serialization.ImplicitReflectionSerializer::class)
on your API. (see keep about experimental annotations for more info)
Make sure to read @ImplicitReflectionSerializer docs in advance to understand the limitations of this approach
6 Views