With JSON schemas, if you want the schema to fail validation if it finds any additional fields you can just throw an "additionalProperties": false on the schema and call it a day, a bit like this:
{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"title": "",
"description": "",
"properties": {
"fieldOne": {
"type": "string",
"description": "Example String"
}
},
"additionalProperties": false
}
However, if I have the following case class/object:
case class MyThing(fieldOne: Option[String])
object MyThing {
implicit val reads: Reads[MyThing] = Json.reads[MyThing]
}
and provide it stuff other than fieldOne, it'll still read the JSON in as a case class correctly but the case class would be empty.
Is there a way to error when additional fields are provided in JSON when reading from JSON to a case class?