Skip to content
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

Conversation

johanandren
Copy link

No description provided.

case None => JsNull
case Some(a) => innerFormat.writes(a)
}
)
Copy link
Author

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 As. 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]
Copy link
Author

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.

@patriknw patriknw force-pushed the wip-docs-PersistentEntity-patriknw branch from 4246bd0 to f872dd6 Compare November 15, 2016 14:45
Copy link
Owner

@patriknw patriknw left a 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]] =
Copy link
Owner

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)

Copy link
Author

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.

Copy link
Owner

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

@johanandren
Copy link
Author

I'll close this and PR against lagom master instead.

patriknw pushed a commit that referenced this pull request May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants