jakiej
10/22/2018, 4:21 PMjcechace
10/22/2018, 8:36 PMval json = JsonObject(mapOf(
"apiId" to JsonPrimitive(obj.apiId),
"organizationId" to JsonPrimitive(obj.organizationId),
// .... endless ...
))
coletz
10/25/2018, 7:41 PMjkbbwr
10/26/2018, 1:51 AMgildor
10/26/2018, 5:18 AMjdemeulenaere
10/26/2018, 9:17 PMcoletz
10/27/2018, 10:06 PMKotlin serialization support consists of three parts: a compiler plugin, which produces visitor/serializer code for objects, an IntelliJ plugin and a runtime library.
Are intellij plugin and compiler plugin open source? I can't find them on githubk_marussy
10/28/2018, 12:08 PMAs.PROPERTY
polymoprhic deserialization (e.g., {"type": "some.class.Name", "property": "value"}
instead of ["some.class.Name", {"property": "value"}]
) with kotlinx.serialization?
I actually have some even more polymorphic gnarly (de)serailization requirements, which I could handle by some pretty ugly custom Jackson (de)serializers, but I would be interested a JVM-idependent solution. A key idea seems to be some kind of lookahead, during which Jackson can put tokens into a TokenBuffer
while searching for the "type"
attribute, and prefix the remaining token stream with the buffer contents upon calling the concrete deserializer. As the JSON schema I have to handle clearly wasn't designed with ease of parsing in mind, I have to rely a lot on lookahead.
I am unsure how to achieve something similar with KInput
and KSerialClassDesc
.thevery
10/29/2018, 3:52 PMNikky
10/30/2018, 1:17 AMNikky
10/30/2018, 1:24 AMplugins
blockjw
10/30/2018, 1:25 AMKen
10/30/2018, 6:00 PMjosephivie
10/31/2018, 5:12 PMNikky
11/01/2018, 9:37 PMkotlin-serialization
, was the plugin renamed ?jakiej
11/02/2018, 12:10 AM{
"a": {
"b": "c"
}
}
to
@Serializable
class Wrapper(val a: Map<String, Any> = mapOf())
what's the easiest way? (if there a way I can specify default (e.g, LinkedHashMap
) for Map and default (String
) for "c"?Nikky
11/02/2018, 10:42 AMJSON.stringify(something)
for now i solved it like this
data class Something(
val someProperty: String
) {
@Serializer(forClass=Something::class)
companion object
}
JSON.parse(Something, string)
is there a better way than adding companion objects to everything ?Nikky
11/06/2018, 6:15 PM<http://logger.info|logger.info>("loading configuration")
val rootFolder = File(".").absoluteFile
val configFolder = rootFolder.resolve("config")
configFolder.mkdirs()
val baseFile = configFolder.resolve("base.hocon")
val parser = ConfigParser()
val config = ConfigFactory.parseFile(baseFile)
println(config)
val baseConfig = parser.parse(config, BaseConfiguration.serializer())
println(baseConfig)
BaseConfiguration is
@Serializable
data class BaseConfiguration (
@Optional var ids: List<Int> = listOf(),
@Optional var strings: List<String> = listOf()
)
Nikky
11/06/2018, 6:35 PMstringify
for typesafe config, is that some limitation of the urrent codegeneration done by kotlinx or did nobody got around to implement that yet ?sandwwraith
11/14/2018, 11:43 AMTasos Stamadianos
11/26/2018, 6:17 PM{
"sessionId": "...",
"commandId": "...",
"message": { ... }
}
So, at a lower layer of my code, I parse the sessionId
and the commandId
using JsonTreeParser
, and using the same parser I extract message
as a JsonObject. Later on, whoever needs to use the message
JsonObject can deserialize to whatever they want using mapper.readTree
.
Now, say I need to serialize back to another format. Specifically:
{
"success": true,
"message": "...",
"commandId": "...",
"payload": { ... }
}
That payload
field is any custom class which needs to be serializable and passed somehow, but I can't find a way to make it a JsonObject, or write any JsonObject for that matter. I also tried making a generic class with an field of the type of payload
, but that didn't seem like the right direction. I guess what I'm asking is, how can I create a JsonObject from an instance of a class?thevery
11/29/2018, 4:52 PMencodeDefaults
and JSON serializer? This case doesn't work for me:
@Serializable data class N(val s: String, val l: List<Int>? = null)
assertEquals("""{"s":"s"}""", JSON(encodeDefaults = false).stringify(N.serializer(), N("s")))
bartvh
11/30/2018, 2:08 PM@Serializer(forClass = Long::class)
object LongStrSerializer : KSerializer<Long> {
override fun deserialize(input: Decoder): Long =
input.decodeString().toLong()
override fun serialize(output: Encoder, obj: Long) =
output.encodeString(obj.toString())
}
@kotlinx.serialization.Serializable
data class PlayerSummary(
@kotlinx.serialization.Serializable(with = LongStrSerializer::class)
val id: Long,
val displayName: String
)
However this still results in:
{
"displayName": "Jessie James",
"id": 1337000000
}
What am I doing wrong?adev_one
12/06/2018, 7:36 AMJsonElemet
as field of @Serializable
class?
Example:
@Serializable
data class Test(
val a: Int,
val b: JsonElement
)
val test = JSON.parse(Test.serializer(), """{"a":1,"b":{"test":"test2"}}""")
println(test.toString())
Lulu
12/12/2018, 9:28 AMkotlinx.serialization.json.JsonParsingException: Invalid JSON at 1221: Expected '[, kind: kotlinx.serialization.UnionKind$POLYMORPHIC@1e6d1014'
thevery
12/13/2018, 9:55 AMLulu
12/13/2018, 11:04 AMhallvard
12/13/2018, 3:42 PMcharleskorn
12/17/2018, 2:29 AMsandwwraith
12/20/2018, 3:19 PM0.10.0-eap-1
(dev branch) has just been released! This is a companion release to Kotlin 1.3.20-eap-52
Highlights:
• Now Native plugin supports generics, @SerialInfo annotations and other features that were missing before
• Now SerialDescriptor.getElementDescriptor
is working and one can use it to deeply inspect descriptors tree
• JSON now can omit default values
• (breaking change) Context serializer is not enabled automatically anymore, use @ContextualSerialization
on property.
Full changelog: https://github.com/Kotlin/kotlinx.serialization/blob/dev/CHANGELOG.mdsandwwraith
12/20/2018, 3:19 PM0.10.0-eap-1
(dev branch) has just been released! This is a companion release to Kotlin 1.3.20-eap-52
Highlights:
• Now Native plugin supports generics, @SerialInfo annotations and other features that were missing before
• Now SerialDescriptor.getElementDescriptor
is working and one can use it to deeply inspect descriptors tree
• JSON now can omit default values
• (breaking change) Context serializer is not enabled automatically anymore, use @ContextualSerialization
on property.
Full changelog: https://github.com/Kotlin/kotlinx.serialization/blob/dev/CHANGELOG.mdJonas Bark
12/20/2018, 4:03 PM