themishkun
06/11/2019, 1:19 PMpacked
fields and all fields in data class are nullable or provided with defaults. Any tips?tylerwilson
06/13/2019, 1:24 AMDavid
06/13/2019, 9:42 AM{}
or the structure that my serialiser expects e.g. {"id": "ABC123", "status": "STATUS"}
. I have tried a number of approaches that i’ve documented on this SO ticket;
https://stackoverflow.com/questions/56541201/parsing-empty-object-with-kotlinx-serialization
Would anyone be able to point out where I am going wrong?Toddobryan
06/13/2019, 4:07 PMencodeDefaults
value for a given field? I have a type
field that I'm using to distinguish subclasses. Obviously, I set the val in each subclass, but when I'm deserializing, I only know it's the superclass and without the type
, there's no way to know which subclass to deserialize to.Paulius Ruminas
06/18/2019, 2:12 PMsealed class A {
@Serializable
data class B(val type: String) : A()
}
@Test
fun main() {
val json = Json(
configuration = JsonConfiguration.Common,
context = SerializersModule {
polymorphic<A> {
addSubclass<A.B>()
}
}
)
val s = PolymorphicSerializer(A::class)
val j = json.stringify(s, A.B(type = "Test"))
json.parse(s, j)
}
The code will produce error: Test is not registered for polymorphic serialization in the scope of class A
The error occurs because there are two type
fields. If it is possible it would be nice that this name clash issue would be reported at compile time or if it is not possible I think there should be a better error message that states that one has two type
fields and it is impossible to resolve the polymorphic type. What do you think?Marc Knaup
06/19/2019, 3:15 PMMarc Knaup
06/19/2019, 7:03 PMkotlinx-serialization-runtime
modules change from 0.11.0
to 0.11.1
?
Having only a common dependency to kotlinx-serialization-runtime:0.11.0
works.
With 0.11.1
this doesn't work anymore. It cannot find the classes and the module has no metadata thus Gradle doesn't automatically resolve common
, jvm
etc.Shan
06/19/2019, 9:58 PMsandwwraith
06/20/2019, 9:46 AM0.11.1
has been released. This release is binary compatible with Kotlin/Native 1.3.40. This is mostly a patch release, see notes here: https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md#v0111--2019-06-19Robert Jaros
06/20/2019, 10:26 PMkotlinx-serialization-runtime-js
module. I've noticed the kotlinx-serialization-runtime-js-0.11.1.jar
contains kotlinx-serialization-kotlinx-serialization-runtime.js
file and the previous kotlinx-serialization-runtime-js-0.11.0.jar
contains kotlinx-serialization-runtime.js
file. Is it intentional or is it a bug?ribesg
06/25/2019, 8:44 AMkotlinx.serialization
?Fudge
06/26/2019, 5:14 PM@Serializable
class Wrapper(val test : Test)
enum class Test {
@SerialName("Bar")
Foo
}
println(json.stringify(Wrapper.serializer(), Wrapper(Test.Foo)))
This prints {test: "Foo"}
, I would've expected {test: "Bar"}
though, what am I doing wrong?Toddobryan
06/27/2019, 6:12 AMJsonElement.booleanOrNull
doesn't check to see whether isString
is true, so parse("true").booleanOrNull
and parse("\"true\"").booleanOrNull
both return true
, even though I think the secord one should return null
.Fudge
06/27/2019, 7:59 AM@Serializable(InlineSerializer::class)
class Inlined(val str :String)
fun main(){
val obj = Inlined("test")
val str = json.stringify(Inlined.serializer(),obj)
assertEquals("\"test\"",str) // And not {"str":"test"}
}
tylerwilson
06/29/2019, 3:46 PMclass MyObject {
@Format("mm/dd/yyyy")
@Serializable(with = MyDateSerializer::class)
val poorlyFormattedDate: Date
}
Any way to get the Format data from within the MyDateSerializer (without writing a whole custom parsing class for every model in my app/library? Thank you!altavir
07/06/2019, 2:18 PMFudge
07/10/2019, 8:40 AMJsonObject
in kotlinx.serialization ?Rostislav Utrobin
07/12/2019, 9:11 AMthana
07/14/2019, 3:38 PMefemoney
07/14/2019, 8:13 PMPHondogo
07/15/2019, 6:20 AMToddobryan
07/15/2019, 11:06 PMwilliam
07/16/2019, 3:38 AMPaulius Ruminas
07/16/2019, 6:33 PMPolymorphicSerializer
for sealed class like this
@Serializable(PolymorphicSerializer::class)
sealed class Response {
@Serializable
data class Success(val token: Token) : Response()
// serializer defined in serial module
object Failure : Response()
}
I found this section in doc comment of @Polymorphic
annotation.
Does not affect sealed classes, because they are gonna be serialized with subclasses automatically with special compiler plugin support which would be added later.
At first I thought I could use @Polymorphic
instead of @Serializable(PolymorphicSerializer::class)
but it does not work that way.
Will this approach change in the future?alex009
07/18/2019, 12:39 PMenum class Status {
@SerialName("1")
ACTIVE,
@SerialName("2")
BLOCKED,
@SerialName("3")
WAIT_UPDATE_PROFILE,
@SerialName("4")
WAIT_APPROVE;
}
but serialization can't parse Status:
kotlinx.serialization.SerializationException: com.icerockdev.generated.ktor.models.RelativeProfileResponse.Status does not contain element with name '1'
enums not support @SerialName
?serebit
07/18/2019, 9:44 PMv79
07/20/2019, 10:16 AMMDCacheItem
which is @Serializable
(and I do, I've got that working fine and have written custom serializers), what do I need to do to serialize a Set<MDCacheItem>
? val jsonData = json.stringify(MDCacheItem.serializer(), setToCache)
is not allowed.turansky
07/22/2019, 9:42 PM1.3.50-eap-5
even with custom serializer.
@Serializable(with=KeySerializer::class)
inline class Key(val source:String)
Error:
Inline class serialization not supported
No problem in 1.3.41
.
Is it planned regression for 1.3.50
?mathew murphy
07/23/2019, 7:25 PMJan Stoltman
07/28/2019, 6:15 AMJan Stoltman
07/28/2019, 6:15 AMsandwwraith
07/29/2019, 9:04 AMJan Stoltman
07/29/2019, 1:55 PM