この例があると、
import io.circe.generic.auto._
import io.circe.shapes._
import io.circe.parser._
import io.circe.syntax._
import shapeless._
case class A[T <: HList](name: String, params: T)
このケース クラスを空でない HList でインスタンス化すると、問題はありません。
scala> A("name", "a" :: HNil).asJson
res1: io.circe.Json =
{
"name" : "name",
"params" : [
"a"
]
}
しかし、この HList が HNil のみの場合、次のエラーが発生します。
scala> A("name", HNil).asJson
<console>:29: error: could not find implicit value for parameter encoder: io.circe.Encoder[A[shapeless.HNil.type]]
A("name", HNil).asJson
^
ケースオブジェクトエンコーダーについて話しているこの質問を読みましたが、HNil (HNil はケースオブジェクト) では機能せず、ドキュメントでそれについて何かを見ました。参考までに、circe 0.6.1 を使用しています。
何か案が?