play-json-refined

Play JSON Reads/Writes for refined types

License

License

Categories

Categories

JSON Data
GroupId

GroupId

com.lunaryorn
ArtifactId

ArtifactId

play-json-refined_2.11
Last Version

Last Version

0.5
Release Date

Release Date

Type

Type

jar
Description

Description

play-json-refined
Play JSON Reads/Writes for refined types
Project URL

Project URL

https://github.com/lunaryorn/play-json-refined
Project Organization

Project Organization

Sebastian Wiesner
Source Code Management

Source Code Management

https://github.com/lunaryorn/play-json-refined

Download play-json-refined_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.lunaryorn/play-json-refined_2.11/ -->
<dependency>
    <groupId>com.lunaryorn</groupId>
    <artifactId>play-json-refined_2.11</artifactId>
    <version>0.5</version>
</dependency>
// https://jarcasting.com/artifacts/com.lunaryorn/play-json-refined_2.11/
implementation 'com.lunaryorn:play-json-refined_2.11:0.5'
// https://jarcasting.com/artifacts/com.lunaryorn/play-json-refined_2.11/
implementation ("com.lunaryorn:play-json-refined_2.11:0.5")
'com.lunaryorn:play-json-refined_2.11:jar:0.5'
<dependency org="com.lunaryorn" name="play-json-refined_2.11" rev="0.5">
  <artifact name="play-json-refined_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.lunaryorn', module='play-json-refined_2.11', version='0.5')
)
libraryDependencies += "com.lunaryorn" % "play-json-refined_2.11" % "0.5"
[com.lunaryorn/play-json-refined_2.11 "0.5"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.11
com.typesafe.play : play-json_2.11 jar 2.6.6
eu.timepit : refined_2.11 jar 0.8.4

test (1)

Group / Artifact Type Version
org.scalacheck : scalacheck_2.11 jar 1.13.4

Project Modules

There are no modules declared in this project.

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:

libraryDependencies += "de.cbley" %% "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.cbley.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–2019 Sebastian Wiesner Copyright 2019 Claudio Bley

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.

Versions

Version
0.5
0.3
0.1