Проблема была на стороне маршрутов. В частности, csvMarshaller
отсутствовал.
import kantan.csv._
import kantan.csv.ops._
val src = StreamConverters
.asOutputStream()
.mapMaterializedValue { os =>
Future {
try {
val ps = List(Person(0, "Nicolas", 38), Person(1, "Kazuma", 1), Person(2, "John", 18))
implicit val personEncoder: RowEncoder[Person] = RowEncoder.caseEncoder(0, 2, 1)(Person.unapply)
val writer = os.asCsvWriter[Person](rfc.withHeader("Column 1", "Column 2", "Column 3"))
ps.foreach { p =>
writer.write(p)
}
writer.close()
} catch {
case e: Throwable => logger.error("failed", e)
}
}
}
implicit val csvStreaming: CsvEntityStreamingSupport = EntityStreamingSupport.csv()
// the missing csvMarshaller causes a runtime exception
implicit val csvMarshaller: ToEntityMarshaller[ByteString] =
Marshaller.withFixedContentType(ContentTypes.`text/csv(UTF-8)`) { bytes =>
HttpEntity(ContentTypes.`text/csv(UTF-8)`, bytes)
}
complete(src)