Skip to content

Instantly share code, notes, and snippets.

@machisuji
Created April 2, 2012 04:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save machisuji/2280858 to your computer and use it in GitHub Desktop.
Save machisuji/2280858 to your computer and use it in GitHub Desktop.
import play.api.libs.json._
implicit object userToJson extends Writes[User] {
def writes(user: User): JsonValue = JsonObject(Seq(
"possiblyTotallyUnrelatedFieldName" -> JsString(user.name)
//, ...
))
}
@delitescere
Copy link

I like this as a way to generate a loosely-coupled outbound message in situations where interpolation in a template (which are far easier to use to communicate what the message format is) exceeds performance requirements. Go type classes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment