Last active
September 3, 2020 14:02
-
-
Save ubourdon/ef3e73c0523b60ee0e7bdf3e682b8b6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object A { | |
sealed trait LotLinkType | |
object LotLinkType { | |
case object Tenant extends LotLinkType | |
case object Owner extends LotLinkType | |
case object Landlord extends LotLinkType | |
} | |
implicit val TenantJsonFmt = jsonSerializeCaseObject(Tenant) | |
implicit val OwnerJsonFmt = jsonSerializeCaseObject(Owner) | |
implicit val LandlordJsonFmt = jsonSerializeCaseObject(Landlord) | |
implicit val LotLinkTypeJsonFmt = new Format[LotLinkType] { | |
override def reads(json: JsValue): JsResult[LotLinkType] = | |
__.read[Tenant.type].map(x => x: LotLinkType) | |
.orElse(__.read[Owner.type].map(x => x: LotLinkType)) | |
.orElse(__.read[Landlord.type].map(x => x: LotLinkType)).reads(json) | |
override def writes(o: LotLinkType): JsValue = o match { | |
case Tenant => Json.toJson(Tenant) | |
case Owner => Json.toJson(Owner) | |
case Landlord => Json.toJson(Landlord) | |
} | |
} | |
} | |
object B { | |
import PatrimonyContactEventModelJsonFmt.LotLinkTypeJsonFmt | |
Json.toJson(Tenant).validate[LotLinkType] | |
Json.toJson(Owner).validate[LotLinkType] | |
Json.toJson(Landlord).validate[LotLinkType] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if i cast Tenant with LotLinkType
Json.toJson(Tenant: LotLinkType).validate[LotLinkType]
that compil