EindbaasExpress / handsonscala-issuemigrator

Part of the HandsOnScala Course
0 stars 0 forks source link

Writer skips fields of case class if they have default value and none was provided #110

Open EindbaasExpress opened 2 years ago

EindbaasExpress commented 2 years ago

Hello,

I have a case class:

case class Been(id: Int, name: String = "sample")

When I start export to json:

implicit val beenRW: ReadWriter[Been] = macroRW[Been]
val b1 = Been(1) // please note that for second field the default is used
println(write(b1, 2))

I get the following output:

{
  "id": 1
}

As you can see the other field (name) was skipped.

How to force it to produce all of the fields regardless whether the default value was used to instantiate the given field or the concreate value was provided during initialization? ID: 343 Original Author: tmichniewski