You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Kotlin support default value for fields, when deserializing, fury should assign default value to field if serialization didn' have that field and not write value.
For example, this is the class when serialization
data classFoo(vals:String)
val foo =Foo("abc")
And this is the class when deserialization.
data classFoo(valint:Int = 10, vals:String)
If we deserialize the data from data class Foo(val s: String), we will get Foo(int=0, s=abc), but we should return Foo(int=10, s=abc)
Is your feature request related to a problem? Please describe
Serialization:
data classFoo(vals:String )
funmain(args:Array<String>) {
val fury =Fury.builder().requireClassRegistration(false).withCompatibleMode(CompatibleMode.COMPATIBLE).build()
Files.write(Paths.get("data"), fury.serialize(Foo(s ="abc")))
}
Deserialization:
data classFoo(valint:Int = 10, vals:String )
funmain(args:Array<String>) {
val fury =Fury.builder().requireClassRegistration(false).withCompatibleMode(CompatibleMode.COMPATIBLE).build()
println(fury.deserialize(Files.readAllBytes(Paths.get("data"))))
// Foo(int=0, s=abc)
}
Feature Request
Kotlin support default value for fields, when deserializing, fury should assign default value to field if serialization didn' have that field and not write value.
For example, this is the class when serialization
And this is the class when deserialization.
If we deserialize the data from
data class Foo(val s: String)
, we will getFoo(int=0, s=abc)
, but we should returnFoo(int=10, s=abc)
Is your feature request related to a problem? Please describe
Serialization:
Deserialization:
Describe the solution you'd like
Here is disassembled java code:
Kotlin generated a constructor for default value:
But it didn't provide this default value as a field, so we can't extract this value using reflection.
We could create a
Foo
object and check fields values:null
, then it's a default valueAnd when deserializiing, use the computed default value to set such fields.
For codegen, wen need to extend
MetaSharedCodecBuilder
. When codegen disabled,MetaSharedSerializer
needs to be extendedDescribe alternatives you've considered
No response
Additional context
#1683
The text was updated successfully, but these errors were encountered: