Support for default values.#56
Support for default values.#56rditerwich wants to merge 5 commits intospray:masterfrom rditerwich:master
Conversation
|
Interesting. Can you provide a more detailed description about how this works? Are there any impliciations for type-safety? What's the expected runtime performance? |
|
I expect no significant runtime performance degradation. There is a little case class Customer(id : Id[Customer] = Id.generate, name : String, When providing this json document: { "name" : "John Smith" }
will result in: Customer(Id("123-34-45-45"), "John Smith", Nil) Type safety: it's as type-safe as reflection can be. |
There was a problem hiding this comment.
Can you please make this a case class:
case class FieldAndDefault[T](name: String, defaultValue: Option[() => T])This way you should be able to remove casting below.
There was a problem hiding this comment.
You're right, much nicer. I've renamed it to Field.
|
Thanks, Ruud, for answering the questions. This looks good to me. Could you add your answers to the commit message in short form? |
|
I actually think that we should make this behavior optional since it can have far-stretching consequences. Think of a PUT REST operation, supplying only some fields. This might have the undesirable effect of resetting fields in a database. I've implemented this now with a boolean parameter on jsonFormatN methods. |
|
👍 |
|
One remaining thing: can you add documentation for this feature to the corresponding section of the README? I think we are then ready to go. Your change doesn't merge cleanly any more because of another change I made. Please just pretend it still does, I will do the merge work in the merge commit when this is otherwise finished. |
|
when will this be released? could really use this functionality, thanks! |
|
Is spray-json being abandoned… Guys? |
|
No, it's not abandoned. |
|
Closing as requested |
With this commit, arguments of case classes that have default value specified (expressions actually) can be ommitted from input json documents when deserializing. Serializing behaviour has not changed. Unit tests are succesful.