play-json-extensions
play-json-extensions copied to clipboard
Play Json extensions and SnakeCase
I wrote this code
{
case class Foo(accountNumber: String)
object Foo {
implicit val config = JsonConfiguration(SnakeCase)
import ai.x.play.json.Jsonx
implicit lazy val jsonFormat = Jsonx.formatCaseClass[Foo]
}
}
Json.parse("""{"account_number":"a"}""").validate[Foo]
If I was not using Play Json extensions, it would have parsed account_number to accountNumber. but with the extensions (in code above). it fails
res11: JsResult[Foo] = JsError(
List((JsPath(List(KeyPathNode("accountNumber"))), List(JsonValidationError(List("error.path.missing"), WrappedArray()))))
)
Hi @abhsrivastava
play-json supports only lowerCamelCase by default. This lib follows that behavior
scala> case class Foo(accountNumber: String)
defined class Foo
scala> implicit val format = play.api.libs.json.Json.format[Foo]
format: play.api.libs.json.OFormat[Foo] = play.api.libs.json.OFormat$$anon$3@388f64f6
scala> play.api.libs.json.Json.parse("""{"account_number":"a"}""").validate[Foo]
res0: play.api.libs.json.JsResult[Foo] = JsError(List((/accountNumber,List(JsonValidationError(List(error.path.missing),WrappedArray())))))