{"action":"opened","issue":{"url":"https://api.github.com/repos/julienrf/play-json-derived-codecs/issues/29","repository_url":"https://api.github.com/repos/julienrf/play-json-derived-codecs","labels_url":"https://api.github.com/repos/julienrf/play-json-derived-codecs/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/julienrf/play-json-derived-codecs/issues/29/comments","events_url":"https://api.github.com/repos/julienrf/play-json-derived-codecs/issues/29/events","html_url":"https://github.com/julienrf/play-json-derived-codecs/issues/29","id":148993054,"number":29,"title":"Subtypes Format definitions","user":{"login":"guizmaii","id":1193670,"avatar_url":"https://avatars.githubusercontent.com/u/1193670?v=3","gravatar_id":"","url":"https://api.github.com/users/guizmaii","html_url":"https://github.com/guizmaii","followers_url":"https://api.github.com/users/guizmaii/followers","following_url":"https://api.github.com/users/guizmaii/following{/other_user}","gists_url":"https://api.github.com/users/guizmaii/gists{/gist_id}","starred_url":"https://api.github.com/users/guizmaii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guizmaii/subscriptions","organizations_url":"https://api.github.com/users/guizmaii/orgs","repos_url":"https://api.github.com/users/guizmaii/repos","events_url":"https://api.github.com/users/guizmaii/events{/privacy}","received_events_url":"https://api.github.com/users/guizmaii/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-17T20:25:45Z","updated_at":"2016-04-17T20:25:45Z","closed_at":null,"body":"Sorry to bother you but I don't understand how to use your lib.\r\n\r\nThis is what I have to serialize/deserialize:\r\n\r\n```scala\r\nsealed trait Location\r\ncase class CityLocation(postal_code: String) extends Location\r\ncase class StoreLocation(store_code: String) extends Location\r\ncase class AddressLocation(\r\n  society: Option[String],\r\n  first_name: String,\r\n  ...\r\n) extends Location\r\n\r\nsealed trait Point[T <: Location] { val location: T; val calendar: Option[Calendar] }\r\ncase class ShippingPoint[T <: Location](\r\n  override val location: T,\r\n  override val calendar: Option[Calendar] = None) extends Point[T]\r\ncase class PickupPoint[T <: Location](\r\n  override val location: T,\r\n  override val calendar: Option[Calendar] = None) extends Point[T]\r\n```\r\n\r\nand some example of corresponding JSONs: \r\n\r\n```\r\n{\r\n  \"type\": \"pickup\",\r\n  \"location\" : {\r\n    \"type\": \"city\",\r\n    \"postal_code\": \"59000\"\r\n  }\r\n}\r\n```\r\n\r\n```\r\n{\r\n  \"type\": \"pickup\",\r\n  \"location\" : {\r\n    \"type\": \"address\",\r\n    \"society\": \"Facebook\",\r\n    \"first_name\": \"Mark\",\r\n    ...\r\n  }\r\n}\r\n```\r\n\r\n```\r\n{\r\n  \"type\": \"shipping\",\r\n  \"location\" : {\r\n    \"type\": \"city\",\r\n    \"postal_code\": \"59000\"\r\n  }\r\n}\r\n```\r\n\r\n```\r\n{\r\n  \"type\": \"shipping\",\r\n  \"location\" : {\r\n    \"type\": \"address\",\r\n    \"society\": \"Facebook\",\r\n    \"first_name\": \"Mark\",\r\n    ...\r\n  }\r\n}\r\n```\r\n\r\nAlso, I have an API that is represented by the following case class:\r\n```scala\r\ncase class BookApi(\r\n  ...\r\n  route: Tuple1[ShippingPoint[AddressLocation]],\r\n  url: Option[String],\r\n  ...\r\n)\r\n\r\nobject BookIn extends TupleJson {\r\n  implicit val format = Json.format[BookIn]\r\n}\r\n```\r\n\r\nAs you showed me, I implemented the `Location` and the `Point` formats as follow:\r\n```scala\r\nobject Location {\r\n  implicit val format: OFormat[Location] =\r\n    derived.flat.oformat(\r\n      (__ \\ \"type\").format[String].inmap(\r\n        tpe => s\"${tpe.capitalize}Location\",\r\n        tpe => tpe.dropRight(\"Location\".length).toLowerCase\r\n      )\r\n    )\r\n}\r\n\r\nobject Point {\r\n  implicit def format[T <: Location: Format]: OFormat[Point[T]] =\r\n    derived.flat.oformat(\r\n      (__ \\ \"type\").format[String].inmap(\r\n        tpe => s\"${tpe.capitalize}Point\",\r\n        tpe => tpe.dropRight(\"Point\".length).toLowerCase\r\n      )\r\n    )\r\n}\r\n```\r\n\r\nMy problem is: the `BookApi` implicit `Format` does not compile: \r\n```scala\r\n[error] BookApi.scala:44: No implicit format for (domain.ShippingPoint[domain.AddressLocation],) available.\r\n```\r\nShould I implement the `Format` for all the subtypes of `Point` and `Location` ? \r\nIf yes, how could I do that ? Can I reuse the `Point` and `Location` definitions ?"}}