Matej Drobnič
07/28/2019, 6:58 PMImplicitReflectionSerializer
?
I want to create generic method to send data classes through Websocket. At the moment I have this:
suspend fun <T> send(item: T, serializer: KSerializer<T>) {
// TODO
}
but it is a bit awkward to always pass the serializer. Since I'm always sending data classes which do not support extension, runtime type is not important to me, I would be fine with just detecting the compile-time type.Dominaezzz
07/29/2019, 6:29 AMJsonObject
member?Dominaezzz
07/29/2019, 9:14 AMdata class Request(val mode: String = "default", val extra: String? = null)
, this produces { "mode": "default", "extra": null }
. Can I get it to omit the field entirely instead of setting it to null
?Dominaezzz
07/29/2019, 11:46 PMclassDiscriminator
per parent class planned?sandwwraith
07/30/2019, 8:21 AMsandwwraith
07/30/2019, 8:57 PMSam
08/01/2019, 6:51 PM{
"type": "V",
"expressions": [
{
"type": "M",
"expr": "5+6"
}
],
"resultType": "success"
}
I started to go down the route of using the polymorphic serializer but I didn't know how to customize the type
output. Should I write my own custom serializer for this type? If so is there a good example of how to do this?Soren Valle
08/01/2019, 9:43 PMpackage index.store.state
import index.model.User
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
@Serializable
data class State(val users: Array<User> = emptyArray())
fun state(): State {
val json = Json(JsonConfiguration.Stable)
return JSON.parse(
json.stringify(
State.serializer(),
State()
)
)
}
It feels cleanish, but it seems like there might/should(?) be a native function I can't find that converts a data class to a kotlin.js.Json object.Dominaezzz
08/02/2019, 10:04 AMJson
without treading experimental?jw
08/02/2019, 6:37 PMserebit
08/03/2019, 1:10 AMkotlinx-serialization-runtime-native
artifact in my project's commonMain
source set, and with Gradle metadata enabled, this propagates to all the source sets (including JVM). That project's build succeeds, but if I publish the project to Maven and attempt to depend on it from another (JVM) project, running the other project fails with the error Exception in thread "main" java.lang.NoClassDefFoundError: kotlinx/serialization/SerializationStrategy
. If I add a manual implementation dependency on the runtime in the second project, this error goes away.kevin.cianfarini
08/06/2019, 2:49 AMCaused by: kotlinx.serialization.SerializationException: Can't locate argument-less serializer for class com.kevincianfarini.saddle.Artist$Impl (Kotlin reflection is not available). For generic classes, such as lists, please provide serializer explicitly.
I've done some searching but none of the solutions I've found have worked.Fudge
08/06/2019, 9:34 AM@Serializable(with = ...::class)
whenever they use the data format?
For example, support UUID:
class MyEncoder : NamedValueEncoder {
fun encodeInt() { ... }
...
fun encodeUUID() { ... }
}
class MyDecoder : NamedValueDecoder {
fun decodeInt() { ... }
...
fun decodeUUID() { ... }
And then users can do:
@Serializable
data class OtherFormats(val uuid: UUID)
Instead of:
@Serializable
data class OtherFormats(@Serializable(with = UuidSerializer::class) val uuid: UUID)
(where UuidSerializer
is the name of a class annotated with @Serializer(forClass=UUID::class)
)Jeremy
08/07/2019, 2:45 AMross_a
08/07/2019, 9:17 PM@ExperimentalUnsignedTypes
@FlowPreview
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
Sergioedcigreja
08/08/2019, 9:53 AMthana
08/08/2019, 1:25 PMSam
08/08/2019, 7:14 PM"mods":{"mod1":""}
"mods":{"mod1":{"comp":">=","point":3}}
Is there a way to construct a class or annotate the property to deal with this?Marc Dietrichstein
08/10/2019, 8:29 AMData
) which is defined in another gradle module (subproject) and the result is the following exception:
Caused by: java.lang.IllegalStateException: Class Data have constructor parameters which are not properties and therefore it is not serializable automatically
at org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializerCodegen.checkSerializability(SerializerCodegen.kt:38)
at org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializerCodegen.generateSerializableClassPropertyIfNeeded(SerializerCodegen.kt:106)
at org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializerCodegen.generate(SerializerCodegen.kt:44)
at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializerCodegenImpl$Companion.generateSerializerExtensions(SerializerCodegenImpl.kt:49)
at org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationCodegenExtension.generateClassSyntheticParts(SerializationCodegenExtension.kt:30)
at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen.generateSyntheticPartsAfterBody(ImplementationBodyCodegen.java:438)
at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:132)
at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:302)
at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:286)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateClassesAndObjectsInFile(PackageCodegenImpl.java:118)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateFile(PackageCodegenImpl.java:137)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:68)
... 44 more
Everything works if the data class is defined in the same gradle module as the serializer though. Has anyone here experienced this as well?Slackbot
08/10/2019, 1:17 PMFudge
08/11/2019, 9:36 AMArraySerializer
? For primitives like ByteArray
Fudge
08/11/2019, 11:26 AMSerialModule
? I can't find where Json
and other formats handle the SerialModule
.Sergioedcigreja
08/12/2019, 9:08 AMFudge
08/13/2019, 10:07 AMNamedValueEncoder
/ NamedValueDecoder
.
class MyClass {
/** **/
}
Doing that in a ElementValueEncoder
is simple enough :
class MyEncoder : ElementValueEncoder(){
fun encodeMyClass(obj : MyClass){
/** **/
}
}
// And then in serializer...
@Serializer(forClass = MyClass)
object MyClassSerializer : KSerializer<MyClass> {
override fun serialize(encoder: Encoder, obj: MyClass) {
if(encoder is MyEncoder){
encoder.encodeMyClass(obj)
}
else error("not supported")
}
}
However, I cannot see how I can do the same thing in a NamedValueEncoder
, as it requires a tag, which I don't know how to generate.
class MyTaggedEncoder : NamedValueEncoder(){
fun encodeTaggedMyClass(tag: String, obj : MyClass){
/** **/
}
}
// And then in serializer...
@Serializer(forClass = MyClass)
object MyClassSerializer : KSerializer<MyClass> {
override fun serialize(encoder: Encoder, obj: MyClass) {
if(encoder is MyTaggedEncoder){
encoder.TaggedMyClass( ??????, obj)
}
else error("not supported")
}
}
I don't have access to the methods that generate the tag, to be used in the area marked as "?????", as they are private in NamedValueEncoder
. There are also no methods that allow Any
class to be encoded in NamedValueEncoder
(of which I don't need to provide a tag myself to) . So how can I encode / decode a tagged MyClass
in this situtation?leandro
08/14/2019, 1:27 PM@Serializable
open class Foo(open val foo: String)
@Serializable
data class Bar(override val foo: String, val bar: String) : Foo(foo)
The compiler is pointing on Bar
that I have foo
declared twice (has duplicate serial name of property foo, either in it or its parents
). I could not find this scenario on the polymorphism doc. Does anyone know how to get around this?altavir
08/16/2019, 1:35 PMMutableMap<Name, @Polymorphic T>
field, where Name
is an inline class. I have custom serializer for name. Is it possible to somehow implement a serializer for the map inheriting polymorphic behavior?Fudge
08/19/2019, 10:37 AMankushg
08/21/2019, 2:20 AMdata class MyClass(val foo: String)
that I can conveniently retrive from dynamic JS by using DynamicObjectParser().parse(js("""{ foo: "bar" }"""), MyClass.serializer())
.
Is there a way that I can do the opposite, going from an instance of MyClass
to a dynamic type JS blob { foo: "bar" }
? The goal is to be able to call into the Kotlin/JS artifact from real-JS and be able to predictably interact with the output without having extra bits of data on it.
I can get to a Map<String, Any?>
using Mapper.mapNullable(MyClass.serializer(), instance)
, but I'm not sure if there's a step that I'm missing after that...ankushg
08/21/2019, 10:21 PMAbstractSerialFormat
implementation for?Fudge
08/22/2019, 7:03 PMkotlinx.serialization.UpdateNotSupportedException: Update is not supported for <class>
exception for custom serializers. This only seems to happen when there are multiple objects which have custom serializers in one serializable class, rather than being related to a specific serializer. I guess I could override patch
in all of my serializers, but what is the meaning of Update
and patch
? Also I feel like I'm not supposed to do this considering the documentation doesn't say to override patch
...Fudge
08/22/2019, 7:03 PMkotlinx.serialization.UpdateNotSupportedException: Update is not supported for <class>
exception for custom serializers. This only seems to happen when there are multiple objects which have custom serializers in one serializable class, rather than being related to a specific serializer. I guess I could override patch
in all of my serializers, but what is the meaning of Update
and patch
? Also I feel like I'm not supposed to do this considering the documentation doesn't say to override patch
...java.lang.IllegalStateException: Reader has not consumed the whole input:
very weirdendStructure
...