-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
87 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
title: "Jsoniter Support" | ||
--- | ||
|
||
# Jsoniter Support | ||
|
||
This module provides refined types codec instances for [Jsoniter Scala](https://github.com/plokhotnyuk/jsoniter-scala). | ||
|
||
## Dependency | ||
|
||
SBT: | ||
|
||
```scala | ||
libraryDependencies += "io.github.iltotore" %% "iron-jsoniter" % "version" | ||
``` | ||
|
||
Mill: | ||
|
||
```scala | ||
ivy"io.github.iltotore::iron-jsoniter:version" | ||
``` | ||
|
||
## Encoder/Decoder instances | ||
|
||
Given `JsonValueCodec` for Iron enables using refined types for JSON serialization/deserialization: | ||
|
||
```scala | ||
import com.github.plokhotnyuk.jsoniter_scala.macros.* | ||
import com.github.plokhotnyuk.jsoniter_scala.core.* | ||
|
||
import io.github.iltotore.iron.* | ||
import io.github.iltotore.iron.constraint.all.* | ||
import io.github.iltotore.iron.jsoniter.given | ||
|
||
case class User(name: String :| Alphanumeric, age: Int :| Positive) | ||
|
||
given JsonValueCodec[User] = JsonCodecMaker.make | ||
|
||
//Encoding | ||
writeToString[User](User("totore", 18)) | ||
|
||
//Decoding | ||
readFromString[User]("""{"name":"totore","age":18}""") | ||
readFromString[User]("""{"name":"totore","age":-18}""") //Error: "Should be positive" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters