Skip to content

Repository files navigation

Play json Mapping

Enhance the ability to create writes and reads from complex case classes graph.

Supports Scala 2.13 and Scala 3.

Installation

Add into your build.sbt the following lines:

resolvers +="GitHub Package Registry" at "https://maven.pkg.github.com/null-vector/play-json-mapping"
credentials ++= {
valtoken= sys.env.get("GITHUB_TOKEN")
token.toSeq.map { t =>Credentials("GitHub Package Registry", "maven.pkg.github.com", "_", t)
}
}
libraryDependencies +="null-vector"%%"play-json-mapping"%"<version>"

GitHub Packages requires a token with read:packages (set GITHUB_TOKEN).

Published packages: https://github.com/null-vector/play-json-mapping/packages

Example

This example use the same model using in play-json examples:

importplay.api.libs.json._importorg.nullvector.api.json.JsonMapper._caseclassLocation(lat: Double, long: Double)
caseclassResident(name: String, age: Int, role: Option[String])
caseclassPlace(name: String, centerLocation: Location, residents: Seq[Resident])
implicitvalw:Writes[Place] = writesOf[Place]
implicitvalr:Reads[Place] = readsOf[Place]
//or just:implicitvalm:Format[Place] = mappingOf[Place]

And use as follow:

valplace=Place(
"Watership Down",
Location(51.235685, -1.309197),
Seq(
Resident("Fiver", 4, None),
Resident("Bigwig", 6, Some("Owsla"))
)
)
valjson:JsValue= place.asJson

Scala Enumerations are also automatic mapping:

caseclassMoney(amount: BigDecimal, currency: Money.Currency)
objectMoneyextendsEnumeration {
typeCurrency=ValuevalARS, BRL, USD, MXN=Value
}
...
implicitvalmoneyMapping:Format[Money] =JsonMapper.mappingOf[Money]

About

Enhance the ability to create writes and reads from complex case classes graph.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages