Support for / respect of default arguments in case class decoders?
Hello,
I'm new to fs2-data and am confused by the last section of the documentation for the generic module. Specifically, it's mentioned that...
Both automatic and semi-automatic decoders support also default values when decoding
...but then it looks in fact like if a row's missing a value in a slot that could be populated by a default value when building an instance of the target case class, that value's not used and instead a DecoderError arises. Here's the snippet:
import fs2.data.csv.generic.auto._
case class MyRowDefault(i: Int = 42, j: Int, s: String)
val decoded = stream.through(decodeUsingHeaders[MyRowDefault]())
// decoded: Stream[[x]Fallible[x], MyRowDefault] = Stream(..)
decoded.compile.toList
// res11: Either[Throwable, List[MyRowDefault]] = Left(
// value = fs2.data.csv.DecoderError: unable to decode '' as an integer in line 3
// )
That doesn't feel like "support" for default values, but rather something like "tolerance" of their existence and incompatibility with an encounter of a row missing a value in a slot for which there's a default. Is the example actually the intended behavior?
Hi, thanks for reporting.
This looks like a regression. I will have a look at it. Or maybe @ybasket knows what could have caused this?
OK, thank you @satabin !
I can confirm this is a bug, default values are only working partially. If the missing field has type String, it succeeds, see https://scastie.scala-lang.org/Hu5LZ0nIRyC18LqFkC8nWQ
But it fails with fields of type Int. I'm not yet sure whether that's a regression or whether it just never came up, but I'll try to find time for attempting a fix during the next days. Thank you for reporting!
Many thanks in advance @ybasket !