Hi! I’ve encountered a missing feature in the kotl...
# serialization
n
Hi! I’ve encountered a missing feature in the kotlinx.serialization library.. We’re using the serialization library for JSON requests and responses and for each request we’re doing we get a response with some data, but the JSON also contains a metadata object describing the response data. We currently aren’t doing anything with the metadata and aren’t planning on using it, so we set the serializer to ignore unknown keys. We really want to validate the incoming JSON using the model. In the past we’ve encountered some unwanted behaviour because either the response data or our model changed.. So basically we want to ignore only specific keys while deserializing (the metadata object). Unfortunately this isn’t possible in the library. I’ve found some issue on the github about this feature and I’ve gone ahead and implemented the feature. I already put up a pull request (https://github.com/Kotlin/kotlinx.serialization/pull/2235). But, how to proceed, just wait until it gets reviewed, or should we discuss it?
a
if you’re looking for a way to ignore properties today, I had a couple of suggestions in this thread: https://kotlinlang.slack.com/archives/C7A1U5PTM/p1670929743885949 TBH I’m not a fan of the annotation approach, but I think it would be useful if KxS provided some easier-to-use functionality for this
n
Thanks Adam, although it’s not as nice I hoped it’s the best solution we have at present and will implement it until we get a better option..
@Adam S I’ve tried out the IgnoredField approach but I can’t get it to work since our
metadata
is an object, so using a primitive descriptor fails. For now I’ve set it to JsonElement, made it private and added the deprecation annotation