Given the following case class and JSON
case class Profile(name: String, `type`: String, value: String, sort: Long = 0)
val json_string = """[
{"name": "Birthday", "type": "DateTime", "value": "12/25/1990"},
{"name": "Fullname", "type": "String", "value": "Birthday Boy"}
]"""
The following call:
val profiles = Json.parse(json_string).as[Seq[Profile]]
Results in the exception:
JsResultException(errors:List(((0)/sort,List(ValidationError(error.path.missing,WrappedArray()))), ((1)/sort,List(ValidationError(error.path.missing,WrappedArray())))))
If I add the a sort
key to my JSON string the deserialization works as expected. Why doesn't the default value for sort
in the case class "kick in" and allow the deserialization?
I'm using JsMacroInception to define the reads/writes
val implicit profileReader = Json[Profile].reads
val implicit profileWriter = Json[Profile].writes
Can I do something with the reader to support the optional constructor parameter?