All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.finch.argonaut.Decoders.scala Maven / Gradle / Ivy

package io.finch.argonaut

import argonaut._
import cats.syntax.either._
import io.finch.Decode
import io.finch.internal.HttpContent

trait Decoders {

  /** Maps Argonaut's [[argonaut.DecodeJson]] to Finch's [[Decode]]. */
  implicit def decodeArgonaut[A](implicit d: DecodeJson[A]): Decode.Json[A] =
    Decode.json { (b, cs) =>
      Parse.parse(b.asString(cs)).flatMap(_.as[A].result.leftMap(_._1)) match {
        case Right(result) => Right(result)
        case Left(error)   => Left(new Exception(error))
      }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy