I am getting this error:
Cannot decode into a value of type com.blah.rest.model.UserProfile,
because no EntityDecoder[cats.effect.IO, com.blah.rest.model.UserProfile]
instance could be found.
for the following case class:
case class UserProfile(id: Option[Int], firstName: String, lastName: String)
Encountered the error on POST
code:
case req @ POST -> Root / "v1" / "profiles" =>
req.as[UserProfile] flatMap {(up: UserProfile) =>
Ok(service.createProfile(up).asJson)
}
With the following POST
body:
{
"firstName": "Jack",
"lastName": "Appleseed"
}
I think this happens when the body is being converted to UserProfile
in req.as[UserProfile]
!
But, this is a plain vanilla case class, the EntityDecoder
should be auto-derived! I know akka-http
does it!
Any ideas/suggestions?
Please Note: Http4sVersion = "0.18.0-M4"
and circe version "0.9.0-M1"
Adding this dependency:
"io.circe" %% "circe-generic" % "0.9.1"
resolved the auto-encoding of case classes to JSON for me.
It allows for the required import: import io.circe.generic.auto._