I have the following case class:
final case class Camel(firstName: String, lastName: String, waterPerDay: Int)
and circe configuration:
object CirceImplicits {
import io.circe.syntax._
import io.circe.generic.semiauto._
import io.circe.{Encoder, Decoder, Json}
import io.circe.generic.extras.Configuration
implicit val customConfig: Configuration =
Configuration.default.withSnakeCaseMemberNames.withDefaults
implicit lazy val camelEncoder: Encoder[Camel] = deriveEncoder
implicit lazy val camelDecoder: Decoder[Camel] = deriveDecoder
}
It is ok, when testing against this:
val camel = Camel(firstName = "Camelbek", lastName = "Camelov", waterPerDay = 30)
private val camelJ = Json.obj(
"firstName" -> Json.fromString("Camelbek"),
"lastName" -> Json.fromString("Camelov"),
"waterPerDay" -> Json.fromInt(30)
)
"Decoder" must "decode camel types" in {
camelJ.as[Camel] shouldBe Right(camel)
}
But this test is not passing:
val camel = Camel(firstName = "Camelbek", lastName = "Camelov", waterPerDay = 30)
private val camelJ = Json.obj(
"first_name" -> Json.fromString("Camelbek"),
"last_name" -> Json.fromString("Camelov"),
"water_per_day" -> Json.fromInt(30)
)
"Decoder" must "decode camel types" in {
camelJ.as[Camel] shouldBe Right(camel)
}
How correctly configure circe in order to be able parsing json with keys in snake case?
I'm using circe version 0.10.0