kantan.csv
kantan.csv copied to clipboard
CellDecoder[LocalDate] not allow white space.
this code become to decode error.
import kantan.csv.java8._
import kantan.csv._
import kantan.csv.ops._
val x =
"""a, 2019-10-12""".stripMargin.readCsvRow[(String, LocalDate)](rfc)
println(x) // Left(TypeError: ' 2019-10-12' is not a valid LocalDate)
CellDecoder[LocalDate] can only parse for a,2019-10-12
or a, "2019-10-12"
.
but, CellDecoder[Long] can parse for a, 123
, because StringCodec[Long] call to String#trim
ref https://github.com/nrinaudo/kantan.codecs/blob/master/core/shared/src/main/scala/kantan/codecs/strings/codecs.scala#L234
why do not apply some solution for LocalDate?
No reason other than I forgot, I'm afraid. I'll fix that in a future release, but that doesn't help you right now.
If you've already dug through the code enough to reach kantan.codecs, you probably worked out the workaround for yourself, but just in case: you can provide your own CellDecoder[LocalDate]
by grabbing the StringDecoder[LocalDate]
, contramapping a trim
into it and tagging it to the right phantom type.
thanks. I will try 👍
Reopening because I do want to fix this properly :)
Hello! Sorry to come here for support. I'm facing a similar issue with an enumeratum and I'm trying to implement a similar workaround.
I succeeded by changing the string decoder globally, but that's not what I really want.
My two questions are:
- How do you "grab" decoders that are otherwise implicitly generated (such as the StringDecoder[LocalDate] you mention above)
- What do you mean by "tagging it to the right phantom type"
Thanks a lot!
Cheers
Well, implicitly
allows you to summon implicit values, such as:
implicitly[StringDecoder[LocalDate]]
Decoders are tagged with a type - kantan.csv.codecs
for CSV decoders, so to turn a StringDecoder[LocalDate]
into a CellDecoder[LocalDate]
, you can call .tag[kantan.csv.codecs]
.