Skip to content

Instantly share code, notes, and snippets.

@tlync
Created October 5, 2013 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlync/6841791 to your computer and use it in GitHub Desktop.
Save tlync/6841791 to your computer and use it in GitHub Desktop.
Single field json serialization using Play's JSON
import play.api.libs.json._
import play.api.libs.functional.syntax._
object Main {
implicit val jsonFormat =
(__ \ "v").write[String].contramap((fb: FizzBuzz) => fb.v)
def main(args: Array[String]) {
print(Json.toJson(FizzBuzz.Fizz))
print(Json.toJson(FizzBuzz.Buzz))
}
}
object FizzBuzz {
case object Fizz extends FizzBuzz("Fizz")
case object Buzz extends FizzBuzz("Buzz")
}
sealed abstract class FizzBuzz(val v: String)
@tlync
Copy link
Author

tlync commented Dec 19, 2013

これはダメ

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