-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for default values. #56
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. |
@@ -25,6 +25,10 @@ import java.lang.reflect.Modifier | |||
trait ProductFormats { | |||
this: StandardFormats => | |||
|
|||
type FieldAndDefault = (String, Option[() => Any]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.