Skip to content

Instantly share code, notes, and snippets.

@mandubian
mandubian / CODE.scala
Last active September 30, 2021 20:03 — forked from playxamplez-admin/CODE
#Json #Reads/#Writes for a sealed #trait & inheriting caseclasses without type indication in Json #Play2.1
import play.api.libs.json._
import play.api.libs.functional.syntax._
sealed trait Shape
case class Circle(c: (Float, Float), r: Float) extends Shape
object Circle {
// reader is covariant and can be implicit in inheriting caseclasses
implicit val reader = Json.reads[Circle]
// writer is contravariant and can't be implicit in inheriting caseclasses
package controllers;
import play.*;
import play.mvc.*;
import views.html.*;
public class Application extends Controller {
public static Result index(String name) {