typesafe-ids-play-json


License

License

MIT
Categories

Categories

JSON Data
GroupId

GroupId

com.github.anshulbajpai
ArtifactId

ArtifactId

typesafe-ids-play-json_2.12
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

typesafe-ids-play-json
typesafe-ids-play-json
Project URL

Project URL

https://github.com/anshulbajpai/typesafe-ids-play-json
Project Organization

Project Organization

com.github.anshulbajpai
Source Code Management

Source Code Management

https://github.com/anshulbajpai/typesafe-ids-play-json

Download typesafe-ids-play-json_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.anshulbajpai/typesafe-ids-play-json_2.12/ -->
<dependency>
    <groupId>com.github.anshulbajpai</groupId>
    <artifactId>typesafe-ids-play-json_2.12</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.anshulbajpai/typesafe-ids-play-json_2.12/
implementation 'com.github.anshulbajpai:typesafe-ids-play-json_2.12:0.1.0'
// https://jarcasting.com/artifacts/com.github.anshulbajpai/typesafe-ids-play-json_2.12/
implementation ("com.github.anshulbajpai:typesafe-ids-play-json_2.12:0.1.0")
'com.github.anshulbajpai:typesafe-ids-play-json_2.12:jar:0.1.0'
<dependency org="com.github.anshulbajpai" name="typesafe-ids-play-json_2.12" rev="0.1.0">
  <artifact name="typesafe-ids-play-json_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.anshulbajpai', module='typesafe-ids-play-json_2.12', version='0.1.0')
)
libraryDependencies += "com.github.anshulbajpai" % "typesafe-ids-play-json_2.12" % "0.1.0"
[com.github.anshulbajpai/typesafe-ids-play-json_2.12 "0.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.6
com.github.anshulbajpai : typesafe-ids_2.12 jar 0.3.0
com.typesafe.play : play-json_2.12 jar 2.6.9

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.0.5

Project Modules

There are no modules declared in this project.

typesafe-ids-play-json

An integration of typesafe-ids with play-json

Build Status Maven Central license

This library helps with play-json's Reads/Writes/Format instance derivation for a typesafe-id type.

Usage

Include typesafe-ids-play-json via SBT from maven central

libraryDependencies += "com.github.anshulbajpai" %% "typesafe-ids-play-json" % "0.1.0"

We support scala 2.11 and 2.12.

If a play-json's implicit Reads/Writes/Format instance for underlying IdType#IdValue is available in the scope, then a corresponding implicit instance for Id[IdType] will be automatically available.

  import com.github.anshulbajpai.typsafeids.core.IdType
  import com.github.anshulbajpai.typsafeids.core.Id
  import com.github.anshulbajpai.typesafeids.json.play.implicits._

  trait UserId extends IdType {
    type IdValue = UUID
  }
  
  val userId: Id[UserId] = Id[UserId](UUID.randomUUID())
  
  // Serialization
  Json.toJson(userId) // will evaluate to JsString(userId.value.toString)
  
  //Deserialization
  val uuid = UUID.randomUUID()
  Json.fromJson[Id[UserId]](JsString(uuid.toString)) // will evaluate to JsSuccess(Id[UserId](userId))

Please note that we had to import com.github.anshulbajpai.typesafeids.json.play.implicits._ in the above example.

The above example work because an implicit Reads/Writes/Format instance for java.util.UUID (provided by play.api.libs.json) is present in scope.

Versions

Version
0.1.0