import argonaut._, Argonaut._
import scala.util.control.NoStackTrace
final case class UncaughtException(error: String) extends RuntimeException with NoStackTrace
implicit val UncaughtExceptionJsonEncoder: EncodeJson[UncaughtException] =
jencode1L((e: UncaughtException) => e.getMessage)("error")
scala> UncaughtExceptionJsonEncoder.encode(UncaughtException("a"))
java.lang.NullPointerException
at scala.collection.immutable.StringOps$.length$extension(StringOps.scala:47)
at scala.collection.immutable.StringOps.length(StringOps.scala:47)
but the following works:
EncodeJson((p: UncaughtException) =>
("error" := p.error) ->: jEmptyObject)
scala> X.encode(UncaughtException("a"))
res1: argonaut.Json = {"error":"a"}```