Skip to content

[Scala] support default not-null value in COMPATIBLE mode. #1683

Description

@LoranceChen

Currently, for scala, add new field and deserialize from old binary data will get a null as new field value. But avoid null is a good practice in scala language.

  val personBytes = readBytesFromFile("person_v1") // there are old version `Person(1,true,some text)`
  //  append field as new person: case class Person(a: Int, b: Boolean, c: String, d: String = "default d")
  val deserPerson = fury.deserializeJavaObject(personBytes, classOf[Person])
  println(s"deserPerson: ${deserPerson}") // deserPerson: Person(1,true,some text,null)

I think it's better using default value our a empty value to set the new field. Such as give the result:

// deserPerson: Person(1,true,some text, "default d")

And if there not a default value in the field define, can give a empty value. For String is "" will be better for null.

If the new field is a structure, can using a default value to instance this one.
case class Foo(a: String, b: Int) can setting the default value as Foo("", 0)

However, for some performance care scenario. Using null should be better and handle by developer.

I'm advice add a new configuration to decide using the default value or null for new field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions