k
🙏
k
with regards to 1): does setting
encodeDefaults
work?
k
Unfortunately not. I believe
encodeDefaults
only works for serializing back to json
k
oh, you're deserializing, and the JSON is missing a property? for me by default that deserializes to a default value, and I usually set those to
null
...
j
did you add
ignoreUnknownKeys = true
?
If it doesn't work, you have to add default parameters
Copy code
@Serializable
data class Some(val property: String? = null)
k
yes, you must have default parameters!
k
Indeed setting to
null
works, but I was hoping to avoid that. Since the field’s already nullable
ignoreUnknownKeys
only works for json keys that don’t exist in my model
k
ignoreUnknownKeys are for a different problem, I'd say
ah I see, I wanted that as well... if the key is nullable, the default should be null without specifying it excplicitly
j
Yep, I think I read about this problem in an issue and default parameters was the only option, maybe that issue has been updated and has a global workaround
k
but I couldn't make it work, don't think there's an option for that - I have
SomeType? = null
basically everywhere
k
I see. That’s too bad. But I guess I can live with this
j
yep, in one project I had to replace it with IntelliJ replace feature because I had a lot of them 😅
k
as far as 4) goes: there's file level anotation
@file::UseSerializers
j
4) should not be solved via JsonModule and add it to the
Json
used by jake converter?
k
for 2) I'm also doing it manually, by implementing a Kserializer for my type... don't think there's an annotation that specifies a default enum value...
k
@Javier I’m using
serializerModule
+
@Contextual
annotation. But I also have another field of the same type but I want a different serializer for that one. So I have to put
@Serializable(with=Serializer::class)
, but I was hoping I could apply this on a custom annotation and then I can do
@CustomAnnotation
instead
🔝 1
@Karlo Lozovina for 2, Moshi has
EnumJsonAdapter#withUnknownFallback
, but kotlinx.serialization doesn’t seem to have anything similar