Skip to content
Branch: master
Go to file

Latest commit


Failed to load latest commit information.
Latest commit message
Commit time

play-json-typedid - TypedId Json Format for Play 2 Scala


This Play plugin provided TypedId Format to map json object into TypedId objects.

    id: "someId",
    someOtherValue: "another Json Property"

// becomes
case class TestId1(value: String) extends StringBaseId
case class Test1(id: TestId1, someOtherValue:String)

Using typedid withing your case classes has a great adavantage when you provide those primary or foreign keys to other service classes. i.e.

// instead of
trait AService {
    def executeSomething(id:String): Future[Boolean]

// you could write
trait AService {
    def executeSomething(id: TestId1): Future[Boolean]


Add the following to build.sbt:

resolvers += "Tegonal releases" at ""

libraryDependencies += "com.tegonal" %% "play-json-typedid" % "1.0.1"


Your id classes must extends from a provided BaseId trait

case class TestId1(value: String) extends StringBaseId
case class TestId2(value: BigDecimal) extends NumberBaseId

For every id class provide an appropriate format

//provide formats for id classes
implicit val testId1Format: Format[TestId1] = Json.idformat[TestId1](TestId1.apply _)
implicit val testId2Format: Format[TestId2] = Json.idformat[TestId2](TestId2.apply _)

After this, id classes can be used within automatically mapped case classes as described in

case class Test3(id: TestId1, foreigId: TestId2)
implicit val test3Format: Format[Test3] = Json.format[Test3]


This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see


Generic Id JSON Formatter for scala and play




You can’t perform that action at this time.