amnaredo / test

0 stars 0 forks source link

Upickle 0.7.1 drops default values in Scala case class #238

Open amnaredo opened 2 years ago

amnaredo commented 2 years ago
import upickle.default.{ReadWriter => RW, macroRW}
import upickle.default.write

object Main extends App {

  val p = Person(age = 90)

  val json = write(p)

  println(json) // {"age":90}

}

case class Person(name: String = "Allan", age: Int)
object Person{
  implicit val rw: RW[Person] = macroRW
}

Name is not present in the converted JSON string ?? ID: 251 Original Author: Allan-Gong

amnaredo commented 2 years ago

this is expected and documented behavior Original Author: lihaoyi

amnaredo commented 2 years ago

@lihaoyi

Can you provide a link to the related documentation ? I can't seem to find it ... Original Author: Allan-Gong

amnaredo commented 2 years ago

@Allan-Gong

http://www.lihaoyi.com/upickle/#Defaults

If a field at serialization time has the same value as the default, uPickle leaves it out of the serialized blob Original Author: raquo