Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/avdv/play-json-refined
Play JSON Reads/Writes instances for refined types
https://github.com/avdv/play-json-refined
json refinement-types scala
Last synced: 10 days ago
JSON representation
Play JSON Reads/Writes instances for refined types
- Host: GitHub
- URL: https://github.com/avdv/play-json-refined
- Owner: avdv
- License: apache-2.0
- Created: 2016-05-11T19:14:54.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-10-27T08:03:22.000Z (10 days ago)
- Last Synced: 2024-10-27T09:18:51.597Z (10 days ago)
- Topics: json, refinement-types, scala
- Language: Scala
- Homepage: https://github.com/avdv/play-json-refined
- Size: 301 KB
- Stars: 24
- Watchers: 5
- Forks: 6
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# play-json-refined
[![Apache 2.0 license](https://img.shields.io/github/license/avdv/play-json-refined)](http://www.apache.org/licenses/LICENSE-2.0)
[![Github workflow status](https://github.com/avdv/play-json-refined/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/avdv/play-json-refined/actions/workflows/test.yml?query=branch%3Amain)[Play JSON][] Reads/Writes instances for [refined][] types.
In other words, this library let’s you convert refined types to and from JSON.[Play JSON]: https://www.playframework.com/documentation/2.8.x/ScalaJson
[refined]: https://github.com/fthomas/refined## Installation
Add the following to your `build.sbt`:
```scala
libraryDependencies += "de.cbley" %% "play-json-refined" % ""
```Replace `` with the desired version, see https://mvnrepository.com/artifact/de.cbley/play-json-refined.
## Usage
``` scala
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 PosIntscala> val foo : PosInt = 42
foo: PosInt = 42scala> Json.toJson(foo)
res0: play.api.libs.json.JsValue = 42scala> 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 BleyLicensed 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 athttp://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.