zio-json
zio-json copied to clipboard
Combine encoding as an array of values and JsonDiscriminator
Hello,
JMAP is encoding some data, called Invocation in the following way:
["nameOfTheMethod", arguments, "clientId"]
It's an array of 3 elements, the first and the third are string, while the second is an object which type depends on the first.
So for example
"""["Mailbox/get", {}, "0"]""".fromJson[Invocation]
should return:
Either[String, MailboxGet] = Right(MailboxGet("Mailbox/get", MailboxGetArguments(...), "0"))
while
"""["Mailbox/query", {}, "0"]""".fromJson[Invocation]
should return:
Either[String, MailboxQuery] = Right(MailboxQuery("Mailbox/query", MailboxQueryArguments(...), "0"))
given:
sealed trait Invocation
case class MailboxGet(methodName: String, args: MailboxGetArguments, clientId: String) extends Invocation
case class MailboxQuery(methodName: String, args: MailboxQueryArguments, clientId: String) extends Invocation
Is there a way to handle this case with zio-json?
@rouazana This is a very specific need. It needs to be handled manually.