-
Notifications
You must be signed in to change notification settings - Fork 0
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
Prepackaged option serializer #1
Prepackaged option serializer #1
Conversation
case None => JsNull | ||
case Some(a) => innerFormat.writes(a) | ||
} | ||
) |
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.
Ofc this breaks down if the innerFormat
serializer also can return JsNull
for some A
s. Not sure we care though - "if it hurts, don't do that"
// box should pick up the implicit serializer? | ||
import Serializers.Implicits._ | ||
|
||
val serializer = Json.format[Box] |
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.
So here the macro pulls in the implicit option serializer for us.
4246bd0
to
f872dd6
Compare
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.
LGTM, pretty nice when you know how to do it
rebase -i
to remove the 3 old commits
* Implicitly provided serializers | ||
*/ | ||
object Implicits { | ||
implicit def optionFormat[A](implicit innerFormat: Format[A]): Format[Option[A]] = |
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.
could this be implicit class ... extends AnyVal
?
(not important since it's not in any hot path)
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 mean that I would create a value class that implements the trait Format
rather than this implicit conversion? Format
seems to be "universal" so I guess maybe it could work, but we are anyways building up a graph of Format
objects to do serialization so I don't think it is worth the effort to look into.
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.
yes, I was thinking about the wrong thing
I'll close this and PR against lagom master instead. |
No description provided.