spray / spray-json

A lightweight, clean and simple JSON implementation in Scala
Apache License 2.0
972 stars 190 forks source link

Add way of rejecting input with extra keys #165

Open wsong opened 8 years ago

wsong commented 8 years ago

If I have a case class like:

case class FoobarClass(optional_value: Option[String] = None)

And I receive input like:

"{"optional_valeu": "test"}" (note that "optional_value" is misspelled)

It'd be nice to be able to throw an exception immediately instead of silently using the default value for optional_value. Is there a way to do this without defining my own RootJsonFormat?

sirthias commented 8 years ago

Currently there is no way to do this but I agree that such a setting would be a valuable thing to have. Thanks for the ticket!

SepidehAlassi commented 4 years ago

@wsong and @sirthias I need the same feature: throw an exception if a field name was not known instead of silently ignoring the object and using the default value of the optional key. Is there any plan to merge [PR #166]?