spray/spray-json — pull request #63 by cvrabie (2013-08-05 18:46:20+00:00)
Title: Added selective field getters for JsObject

When writing a custom `JsonFormat` the currently proposed way of using pattern matching/extractors on `JsObject.getFields` is elegant and concise especially when all the fields are required.

However we often meet the situation where, even though the fields in the domain object are required, we can provide default values for some of these fields, thus making some part of the incoming json optional.

For example, a `User` class might require a `language` and `timezone` parameters but we we can use the system defaults if the incoming json does not specify these fields.

I experimented with multiple options that would make easier the writing of `JsonFormat`s that allow optional fields and I think the best one is to add specialised field getters in the JsObject class. Then `flatMap`/`map` or a for comprehension can be used in the `JsonFormat` to extract the fields as demonstrated in the test.