These are chat archives for nrinaudo/kantan.csv

Jan 2017
Jan 17 2017 02:25
@nrinaudo I mean that I has a case class that has 21 fields (no option field, all field is String). If the CSV has 20 columns, it parse to success but I want to parsing to fail.
case class AuthorCsv(
    code:             String,
    status:           String,
    kanjiName:        String,
    kanaName:         String,
    penName:          String,
    brainCode:        String,
    pic:              String,
    contractType:     String,
    routeMStage:      String,
    gender:           String,
    dob:              String,
    postCode:         String,
    currentAddress:   String,
    phoneNumber:      String,
    emergencyContact: String,
    email:            String,
    hasIdCard:        String,
    reasonOfContract: String,
    note:             String,
    errors:           String,
    uploadDate:       String
val rowDecoder: RowDecoder[AuthorCsv] = RowDecoder.decoder(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)(AuthorCsv.apply)
Nicolas Rinaudo
Jan 17 2017 06:32
Oh, right. You have a stringly typed case class. The problem comes from the fact that it's actually legal for the last cell to be empty - it maps to an empty string. Do you think you could use better types?
@yesterday192 for instance, you could use a date type (joda, java 8, legacy) for uploadDate. That'd sort your problem.
Nicolas Rinaudo
Jan 17 2017 08:24
another improvement on your code: instead of using RowDecoder.decoder, use RowDecoder.ordered. In your use case, it allows you not to specify the column indexes
one last possible improvement, if you're not averse to a shapeless dependency, is to depend on the generic module:
that way, you won't actually need to declare a RowDecoder instance. It might also sort your problem out, since the generic module is a lot stricter about what it allows.