ivan.savytskyi
09/11/2020, 8:23 PMJsonLiteral
has changed. It's now internal
and body
is no longer field on class. We have some business logic that was relying on getting access to raw value body
to understand what type is that value. Now looks like there is no way to say what type was the value when JsonPrimitive
was created. The only hint isString
flag that doesn't really helps. What was the main rationale of hiding JsonLiteral
and body
? Is there any plans to introduce more subclasses of JsonPrimitive
like JsonNumberPrimitive
, JsonBooleanPrimitive
to better represent the primitive value type?Jan Skrasek
09/14/2020, 1:08 PMmelatonina
09/16/2020, 11:03 AMencoder.beginCollection()
, in particular.
The signature is fun beginCollection(desc: SerialDescriptor, collectionSize: Int, vararg typeParams: KSerializer<*>)
. What is desc
the descriptor of? What are the typeParams
?
I can't upgrade to 0.20.0 because I can't use the compiler beyond 1.3.61 at the moment (Arrow meta won't work).zeugederunity
09/16/2020, 5:27 PMSerialName
annotation was set to retention(BINARY)
Is there any way in Kotlin 1.4.x with Serialization 1.0.0-RC to retrieve the SerialName
of an annotated property? Because reflection is now not possible anymore.Ryan Batchelder
09/16/2020, 5:34 PMDynamicObjectParser
into Json
, but when trying to use .decodeFromDynamic()
I'm getting
IllegalStateException: This serializer can be used only with Json format.Expected Decoder to be JsonDecoder, got class DynamicInput
The serializer in this case is a small data class annotated with @Serializable
, and I've also tried using JsonObject.serializer()
with the same results. How can I handle serializing a dynamic from a JS library into a Kotlin object in this case?TwoClocks
09/16/2020, 8:56 PMType mismatch: inferred type is ByteArray but DeserializationStrategy<TypeVariable(T)> was expected
TwoClocks
09/16/2020, 10:19 PMkotlinx.serialization.cbor.internal.CborDecodingException: Expected start of array, but found BF
@Serializable
sealed class BaseClass()
@Serializable
data class TypeOne(val name:String) : BaseClass()
@Serializable
data class TypeTwo(val num:Int) : BaseClass()
@ExperimentalSerializationApi
fun main(args: Array<String>) {
val bb = Cbor.encodeToByteArray(TypeOne("my name is mud"))
val msg = Cbor.decodeFromByteArray<BaseClass>( bb )
println(msg)
}
TwoClocks
09/17/2020, 2:18 AMBaseClass()
includes the type info. But encoding just one (or a list of one) of the subtypes will not generate the "type":
field in the result. How do you force the type info to be present?Greg Steckman
09/20/2020, 5:10 PM@Serializable
class OuterTestClass(val x: Int){
val inner = InnerTestClass(5)
@Serializable
inner class InnerTestClass(val y: Int){
fun compute(): Int{
return x*y
}
}
}
Example test, where a null pointer exception is thrown at the call to o2.inner.compute():
@Test
fun testInnerClassesAreSerializable(){
val o1 = OuterTestClass(3)
val str = Json.encodeToString(o1)
val o2 = Json.decodeFromString<OuterTestClass>(str)
assertEquals(o1.x, o2.x)
assertEquals(o1.inner.y, o2.inner.y)
assertEquals(o1.inner.compute(), o2.inner.compute())
}
The intermediate JSON string looks like what I would expect: {"x":3,"inner":{"y":5}}
I am using Kotlin 1.4.10 and Kotlinx Serialization version 1.0.0-RC. I checked the serialization documentation for any exclusions for inner class support but didn't find anything that looked relevant, and also checked open issues on Github. Does anyone know if this is an intentional unsupported use case, or otherwise a known open issue? Thanks.sandwwraith
09/21/2020, 3:36 PM1.0.0-RC2
has been released! This RC contains tweaks and changes based on users feedback after 1.0.0-RC.
Important highlights:
* JSON serial format was moved to separate kotlinx-serialization-json
artifact to keep core lightweight. You may need to update your buildscripts and replace -core
with -json
.
* encodeDefaults
is now false
by default because this seems to be a more popular setting.
* Fixed several critical bugs (including problems with Android API < 24 and Native ObjC interop).
For full changelog and migration guide, see either CHANGELOG.md
in repository or release notes: https://github.com/Kotlin/kotlinx.serialization/releases/tag/v1.0.0-RC2Robert Jaros
09/21/2020, 4:18 PMleandro
09/24/2020, 1:03 PM1.0.0-RC2
(did not happen with 1.0.-RC
) with my custom serializer using Json.
It’s minified by the stacktrace contains this piece:
Caused by: kotlinx.serialization.SerializationException: Serializer for class 'k' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
Sourabh Rawat
09/26/2020, 5:49 AMdata class Foo(val id: String, val uris: List<String>, val option: Option)
data class Option(val bar: String)
Foo("123", listOf("123", "345"), Option("abc"))
into
["123", ["123, "345"], { "bar": "abc" }]
Foo is simply an example. I want to serialize any data class.Ian
09/26/2020, 6:12 AMfun main() {
@Serializable data class Foo(val nn : Int?)
val s = ProtoBuf.encodeToByteArray(Foo.serializer(), Foo(null))
}
But get:
Exception in thread "main" kotlinx.serialization.SerializationException:
'null' is not supported in ProtoBuf
I've also tried using:
val s = ProtoBuf { encodeDefaults = false }.encodeToByteArray(Foo.serializer(), Foo(null))
But this doesn't help.
Any pointers appreciated.Venkat , Bangalore , India
09/27/2020, 6:14 AMJustin
09/29/2020, 2:35 AMcoolchandrakumar
09/29/2020, 5:15 AMcom.google.protobuf.InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field.
at com.google.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:1563)
Android Project
using protobuf lite pluginVinod Rai
09/29/2020, 8:51 AM-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.SerializationKt
-keep,includedescriptorclasses class com.yourcompany.yourpackage.**$$serializer { *; } # <-- change package name to your app's
-keepclassmembers class com.yourcompany.yourpackage.** { # <-- change package name to your app's
*** Companion;
}
-keepclasseswithmembers class com.yourcompany.yourpackage.** { # <-- change package name to your app's
kotlinx.serialization.KSerializer serializer(...);
}
The package name is changed,..getting exception .. I am using 1.0.0-RC
Serializer for class 'e' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
Data classes are in shared code.
Why progaurd configuration is not working with minify enabled. can anyone help what I am missing here?fkrauthan
10/01/2020, 2:12 AMaltavir
10/01/2020, 7:34 AMSourabh Rawat
10/02/2020, 2:25 AM{
"id": 123
}
how can I configure serialization to automatically populate nullable values and lists in class
data class Foo(val id: Int, val bar: String?, val foobar: List<String>)
I want json to be converted to
Foo(id = 123, bar = null, foobar = emptyList())
spand
10/02/2020, 9:34 AMkotlinx.serialization.json.Json
object. Can I ask it if it is configured to serialize a given KClass
or if it will throw an exception when encountering instances of that type ?Tomas Kormanak
10/02/2020, 9:52 AMdata
property.
@Serializable
data class Sample(
val name:String,
val data: Any
)
Robert Jaros
10/04/2020, 2:33 PM@Serializable
annotation:
SerializationException: Serializer for class 'Test' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
On Kotlin/JS explicitly declared serializer should be used for interfaces and enums without @Serializable annotation
It works when I use @Serializable
, but the documentation states enum do not need this annotation:
https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/builtin-classes.md#enum-classesMatt Toal
10/05/2020, 8:31 PMleandro
10/06/2020, 11:42 AM__type
and another called message
) from my api, modeled using Retrofit and a generic response such as NetworkResponse<MyResponse, ErrorResponse>
, in which the ErrorResponse
is the sealed class in question.
Analysing the returned type with the debugger shows me that my generic response is
UnknownError(error=kotlinx.serialization.json.internal.JsonDecodingException: Polymorphic serializer was not found for missing class discriminator ('null')
JSON input: {"__type":"UserLambdaValidationException","message":"..."})
I’m using v1.0.0-RC, and unsure how to proceed.sandwwraith
10/08/2020, 3:40 PM1.0.0
has been released! This is a public stable release. The definitions of stability and backwards compatibility guarantees are located in the corresponding document: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/compatibility.md.
We now also have a GitHub Pages site with full API reference: https://kotlin.github.io/kotlinx.serialization/.
There are little changes compared to RC2, however, all previously deprecated declarations and migrations were deleted.
If you are using RC/RC2 along with deprecated declarations, please, migrate before updating to 1.0.0.
You can study changelog (https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md) for help.
In case you are using pre-1.0 versions (e.g. 0.20.0), please refer to our migration guide: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/migration.md.tylerwilson
10/08/2020, 6:14 PM@DateSerializer(format = "dd/MM/yyy")
val date: Date
basher
10/08/2020, 6:17 PM@Serialization(forClass:…
?why
10/08/2020, 7:51 PMwhy
10/08/2020, 7:51 PMMranders
10/09/2020, 7:48 AM@Serializable
class E(val s: String)
fun main() {
val listOfEs = listOf(E("foo"), E("bar"), E("baz"))
val eListSerializer = ListSerializer(E.serializer())
val serialized = Json.Default.encodeToString(eListSerializer, listOfEs)
println(serialized)
}
Result: [{"s":"foo"},{"s":"bar"},{"s":"baz"}]why
10/09/2020, 8:20 AMimport kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
val listOfEs = listOf(1, 2, 34)
val serialized = Json.Default.encodeToString(listOfEs)
println(serialized) // result: [1,2,34]
I wanna be able to do this :
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
val myList = MyListImplementation(1, 2, 34)
val serialized = Json.Default.encodeToString(myList)
println(serialized) // result: [1,2,34]
sandwwraith
10/09/2020, 8:59 AMListSerializer(...)
why
10/09/2020, 9:56 AM