I am switching to kotlin 1.5.21 and serialization ...
# serialization
a
I am switching to kotlin 1.5.21 and serialization 1.2.2 and getting error:
kotlinx.serialization.MissingFieldException: Field 'properties' is required for type with serial name 'solid.box', but it was missing.
The
propertiese
field has default null value and is declared like
Copy code
public var properties: Config? = null
        protected set
The error is thrown when trying deserialize descendant that has the default null value. Seems like a bug to me.
Made a reproducer. Filing a bug-report.
p
@altavir I have the same issue too, did you managed to find a workaround or a solution?
a
Not yet, it is a regression in newer kotlin version. In the past it helped to create a class with overriding property in the same module where you use it. The problem occurs only when the property is declared in different module.
👍 1
p
So if we have a BaseApiResponse model, with optional values, we can’t use it for now?
a
Let me check if this workarround works. But in general you just create an intermediate class that just dublicates necessary fields without additional code.
p
Could you please provide an example?
a
I've just checked and the workaround works fine. The idea is following: You have an abstract implementation like
class Abstract(val v: Double)
in one module and class
class Impl(): Abstract()
in another module. You mark
v
as
@Transient
and introduce another class
AbstractInMyModule: Abstract
and dublicate the field there (just mirror it from the parent). Then you make
Imple():AbstractInMyModule
and it works. I can push the working code later because I planned to work on this problem myself today. It is a crutch, but you can remove intermediate class later, when the problem is fixed, without breaking the API.
👍 1
p
Seems as handy as it could get, thanks a lot!
a
I've used this before the problem with multiple modules was fixed somewhere in 1.4. I hope they will fix it again soon.
p
Worked like a charm. Thanks 🙂
Fun fact: if you add a
@Transient
variable in class
Impl()
the workaround doesn’t work anymore.
a
It should not. The transient is done to avoid field duplication. But it should be declared as serializable at some level. The serialization inheritance across modules is probably the main source of different bugs for the frameworks. I guess not a lot of people are using it.