Skip to content
Play JSON Reads/Writes instances for refined types
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
project
src
.gitignore
.scalafmt.conf
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE
README.md
alias.sbt
build.sbt

README.md

play-json-refined

Bintray Apache 2.0 license Travis master build status

Play JSON Reads/Writes instances for refined types. In other words, this library let’s you convert refined types to and from JSON.

Installation

Add the following to your build.sbt:

resolvers += Resolver.bintrayRepo("lunaryorn", "maven")
libraryDependencies += "de.swsnr" %% "play-json-refined" % "<version>"

Replace <version> with the desired version (see Bintray badge above).

Usage

import eu.timepit.refined._
import eu.timepit.refined.auto._
import eu.timepit.refined.api._
import play.api.libs.json._
import de.swsnr.refined.play.json._
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_65).
Type in expressions for evaluation. Or try :help.

scala> type PosInt = Int Refined numeric.Positive
defined type alias PosInt

scala> val foo : PosInt = 42
foo: PosInt = 42

scala> Json.toJson(foo)
res0: play.api.libs.json.JsValue = 42

scala> Json.fromJson[PosInt](JsNumber(42))
res3: play.api.libs.json.JsResult[PosInt] = JsSuccess(42,)

scala> Json.fromJson[PosInt](JsNumber(-42))
res4: play.api.libs.json.JsResult[PosInt] =
JsError(List((,List(ValidationError(List(Predicate failed: (-42 >
0).),WrappedArray())))))

License

Copyright 2016–2018 Sebastian Wiesner

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You can’t perform that action at this time.