ZIO JSON Support

This module provides refined types Encoder/Decoder instances for ZIO JSON.

Dependency

SBT:

libraryDependencies += "io.github.iltotore" %% "iron-zio-json" % "version"

Mill:

ivy"io.github.iltotore::iron-zio-json:version"

Following examples' dependencies

SBT:

libraryDependencies += "dev.zio" %% "zio-json" % "0.3.0"

Mill:

ivy"dev.zio::zio:0.3.0"

Encoder/Decoder instances

Given Encoder/Decoder for Iron enables using refined types for JSON serialization/deserialization:

import zio.json.*

import io.github.iltotore.iron.*
import io.github.iltotore.iron.constraint.all.*
import io.github.iltotore.iron.zioJson.given

case class User(name: String :| Alphanumeric, age: Int :| Positive)

given JsonCodec[User] = DeriveJsonCodec.gen

//Encoding
User("Iltotore", 8).toJson //{"name":"Iltotore", "age":18}

//Decoding
"""{"name":"Iltotore","age":18}""".fromJson[User] //Right(User(Iltotore, 18))
"""{"name":"Iltotore","age":-18}""".fromJson[User] //Left(.age(Should be greater than 0))