Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val format = fields.length match {
- case 0 => c.abort(c.enclosingPosition, "Cannot create json formatter for case class with no fields")
- case 1 =>
- // Only one field, use the serializer for the field
- q"""
- implicit val jsonAnnotationFormat = {
- import play.api.libs.json._
- Format(
- __.read[${fields.head.tpt}].map(s => ${className.toTermName}(s)),
- new Writes[$className] { def writes(o: $className) = Json.toJson(o.${fields.head.name}) }
- )
- }
- """
- case _ =>
- // More than one field, use Play's Json.format[T] macro
- q"implicit val jsonAnnotationFormat = play.api.libs.json.Json.format[$className]"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement