Scala, ZIO, Json - how to deserialize circe json response?

251 Views Asked by At

I have a strange problem with deserialization from external service. I have some lib where I call method and pass params. This method always returns zio.IO[Error, Value]. Inside this lib some magic happens, it connects with other service, get response and return it to me. I create a simple for comprehension example, where I call this method:

for {
  response <- library.someMethod(firstParam, secondParam).map(value => value.code).mapError(error => showError(error))
} yield response

Error and Value here zio.IO[Error, Value] are some custom objects. When I ran this for comprehension code, I got an error, connected with serialization:

The Either on which value was invoked was not defined as a Right; it was Left(sttp.client3.DeserializationException: expected json value got 'Intern...' (line 1, column 1)).
org.scalatest.exceptions.TestFailedException: The Either on which value was invoked was not defined as a Right; it was Left(sttp.client3.DeserializationException: expected json value got 'Intern...' (line 1, column 1)).
    at org.scalatest.EitherValues$Valuable.value(EitherValues.scala:211)

I'm not sure if I need additional decoders or I should change something in for comprehension code to deserialize this value and error? Is it possible to deserialize response and take value correctly?

0

There are 0 best solutions below