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

sjsonnew.UnionFormats.scala Maven / Gradle / Ivy

// auto-generated by sbt-boilerplate
package sjsonnew

import scala.reflect.ClassTag

trait UnionFormats {
  private[this] type JF[A] = JsonFormat[A] // simple alias for reduced verbosity

  /** *BEWARE*:  A1 must be a concrete leaf type, and not an interface. */
  def unionFormat1[U, A1 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2 must be a concrete leaf type, and not an interface. */
  def unionFormat2[U, A1 :JF: ClassTag, A2 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3 must be a concrete leaf type, and not an interface. */
  def unionFormat3[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4 must be a concrete leaf type, and not an interface. */
  def unionFormat4[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5 must be a concrete leaf type, and not an interface. */
  def unionFormat5[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6 must be a concrete leaf type, and not an interface. */
  def unionFormat6[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7 must be a concrete leaf type, and not an interface. */
  def unionFormat7[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8 must be a concrete leaf type, and not an interface. */
  def unionFormat8[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9 must be a concrete leaf type, and not an interface. */
  def unionFormat9[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10 must be a concrete leaf type, and not an interface. */
  def unionFormat10[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10,  A11 must be a concrete leaf type, and not an interface. */
  def unionFormat11[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag, A11 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]
    lazy val a11Format = implicitly[JF[A11]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
        case x if implicitly[ClassTag[A11]].runtimeClass == x.getClass => a11Format.write(x.asInstanceOf[A11], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A11]].runtimeClass) == x => a11Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10,  A11,  A12 must be a concrete leaf type, and not an interface. */
  def unionFormat12[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag, A11 :JF: ClassTag, A12 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]
    lazy val a11Format = implicitly[JF[A11]]
    lazy val a12Format = implicitly[JF[A12]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
        case x if implicitly[ClassTag[A11]].runtimeClass == x.getClass => a11Format.write(x.asInstanceOf[A11], builder)
        case x if implicitly[ClassTag[A12]].runtimeClass == x.getClass => a12Format.write(x.asInstanceOf[A12], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A11]].runtimeClass) == x => a11Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A12]].runtimeClass) == x => a12Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10,  A11,  A12,  A13 must be a concrete leaf type, and not an interface. */
  def unionFormat13[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag, A11 :JF: ClassTag, A12 :JF: ClassTag, A13 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]
    lazy val a11Format = implicitly[JF[A11]]
    lazy val a12Format = implicitly[JF[A12]]
    lazy val a13Format = implicitly[JF[A13]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
        case x if implicitly[ClassTag[A11]].runtimeClass == x.getClass => a11Format.write(x.asInstanceOf[A11], builder)
        case x if implicitly[ClassTag[A12]].runtimeClass == x.getClass => a12Format.write(x.asInstanceOf[A12], builder)
        case x if implicitly[ClassTag[A13]].runtimeClass == x.getClass => a13Format.write(x.asInstanceOf[A13], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A11]].runtimeClass) == x => a11Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A12]].runtimeClass) == x => a12Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A13]].runtimeClass) == x => a13Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10,  A11,  A12,  A13,  A14 must be a concrete leaf type, and not an interface. */
  def unionFormat14[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag, A11 :JF: ClassTag, A12 :JF: ClassTag, A13 :JF: ClassTag, A14 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]
    lazy val a11Format = implicitly[JF[A11]]
    lazy val a12Format = implicitly[JF[A12]]
    lazy val a13Format = implicitly[JF[A13]]
    lazy val a14Format = implicitly[JF[A14]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
        case x if implicitly[ClassTag[A11]].runtimeClass == x.getClass => a11Format.write(x.asInstanceOf[A11], builder)
        case x if implicitly[ClassTag[A12]].runtimeClass == x.getClass => a12Format.write(x.asInstanceOf[A12], builder)
        case x if implicitly[ClassTag[A13]].runtimeClass == x.getClass => a13Format.write(x.asInstanceOf[A13], builder)
        case x if implicitly[ClassTag[A14]].runtimeClass == x.getClass => a14Format.write(x.asInstanceOf[A14], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A11]].runtimeClass) == x => a11Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A12]].runtimeClass) == x => a12Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A13]].runtimeClass) == x => a13Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A14]].runtimeClass) == x => a14Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10,  A11,  A12,  A13,  A14,  A15 must be a concrete leaf type, and not an interface. */
  def unionFormat15[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag, A11 :JF: ClassTag, A12 :JF: ClassTag, A13 :JF: ClassTag, A14 :JF: ClassTag, A15 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]
    lazy val a11Format = implicitly[JF[A11]]
    lazy val a12Format = implicitly[JF[A12]]
    lazy val a13Format = implicitly[JF[A13]]
    lazy val a14Format = implicitly[JF[A14]]
    lazy val a15Format = implicitly[JF[A15]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
        case x if implicitly[ClassTag[A11]].runtimeClass == x.getClass => a11Format.write(x.asInstanceOf[A11], builder)
        case x if implicitly[ClassTag[A12]].runtimeClass == x.getClass => a12Format.write(x.asInstanceOf[A12], builder)
        case x if implicitly[ClassTag[A13]].runtimeClass == x.getClass => a13Format.write(x.asInstanceOf[A13], builder)
        case x if implicitly[ClassTag[A14]].runtimeClass == x.getClass => a14Format.write(x.asInstanceOf[A14], builder)
        case x if implicitly[ClassTag[A15]].runtimeClass == x.getClass => a15Format.write(x.asInstanceOf[A15], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A11]].runtimeClass) == x => a11Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A12]].runtimeClass) == x => a12Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A13]].runtimeClass) == x => a13Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A14]].runtimeClass) == x => a14Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A15]].runtimeClass) == x => a15Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10,  A11,  A12,  A13,  A14,  A15,  A16 must be a concrete leaf type, and not an interface. */
  def unionFormat16[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag, A11 :JF: ClassTag, A12 :JF: ClassTag, A13 :JF: ClassTag, A14 :JF: ClassTag, A15 :JF: ClassTag, A16 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]
    lazy val a11Format = implicitly[JF[A11]]
    lazy val a12Format = implicitly[JF[A12]]
    lazy val a13Format = implicitly[JF[A13]]
    lazy val a14Format = implicitly[JF[A14]]
    lazy val a15Format = implicitly[JF[A15]]
    lazy val a16Format = implicitly[JF[A16]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
        case x if implicitly[ClassTag[A11]].runtimeClass == x.getClass => a11Format.write(x.asInstanceOf[A11], builder)
        case x if implicitly[ClassTag[A12]].runtimeClass == x.getClass => a12Format.write(x.asInstanceOf[A12], builder)
        case x if implicitly[ClassTag[A13]].runtimeClass == x.getClass => a13Format.write(x.asInstanceOf[A13], builder)
        case x if implicitly[ClassTag[A14]].runtimeClass == x.getClass => a14Format.write(x.asInstanceOf[A14], builder)
        case x if implicitly[ClassTag[A15]].runtimeClass == x.getClass => a15Format.write(x.asInstanceOf[A15], builder)
        case x if implicitly[ClassTag[A16]].runtimeClass == x.getClass => a16Format.write(x.asInstanceOf[A16], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A11]].runtimeClass) == x => a11Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A12]].runtimeClass) == x => a12Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A13]].runtimeClass) == x => a13Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A14]].runtimeClass) == x => a14Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A15]].runtimeClass) == x => a15Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A16]].runtimeClass) == x => a16Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10,  A11,  A12,  A13,  A14,  A15,  A16,  A17 must be a concrete leaf type, and not an interface. */
  def unionFormat17[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag, A11 :JF: ClassTag, A12 :JF: ClassTag, A13 :JF: ClassTag, A14 :JF: ClassTag, A15 :JF: ClassTag, A16 :JF: ClassTag, A17 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]
    lazy val a11Format = implicitly[JF[A11]]
    lazy val a12Format = implicitly[JF[A12]]
    lazy val a13Format = implicitly[JF[A13]]
    lazy val a14Format = implicitly[JF[A14]]
    lazy val a15Format = implicitly[JF[A15]]
    lazy val a16Format = implicitly[JF[A16]]
    lazy val a17Format = implicitly[JF[A17]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
        case x if implicitly[ClassTag[A11]].runtimeClass == x.getClass => a11Format.write(x.asInstanceOf[A11], builder)
        case x if implicitly[ClassTag[A12]].runtimeClass == x.getClass => a12Format.write(x.asInstanceOf[A12], builder)
        case x if implicitly[ClassTag[A13]].runtimeClass == x.getClass => a13Format.write(x.asInstanceOf[A13], builder)
        case x if implicitly[ClassTag[A14]].runtimeClass == x.getClass => a14Format.write(x.asInstanceOf[A14], builder)
        case x if implicitly[ClassTag[A15]].runtimeClass == x.getClass => a15Format.write(x.asInstanceOf[A15], builder)
        case x if implicitly[ClassTag[A16]].runtimeClass == x.getClass => a16Format.write(x.asInstanceOf[A16], builder)
        case x if implicitly[ClassTag[A17]].runtimeClass == x.getClass => a17Format.write(x.asInstanceOf[A17], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A11]].runtimeClass) == x => a11Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A12]].runtimeClass) == x => a12Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A13]].runtimeClass) == x => a13Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A14]].runtimeClass) == x => a14Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A15]].runtimeClass) == x => a15Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A16]].runtimeClass) == x => a16Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A17]].runtimeClass) == x => a17Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10,  A11,  A12,  A13,  A14,  A15,  A16,  A17,  A18 must be a concrete leaf type, and not an interface. */
  def unionFormat18[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag, A11 :JF: ClassTag, A12 :JF: ClassTag, A13 :JF: ClassTag, A14 :JF: ClassTag, A15 :JF: ClassTag, A16 :JF: ClassTag, A17 :JF: ClassTag, A18 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]
    lazy val a11Format = implicitly[JF[A11]]
    lazy val a12Format = implicitly[JF[A12]]
    lazy val a13Format = implicitly[JF[A13]]
    lazy val a14Format = implicitly[JF[A14]]
    lazy val a15Format = implicitly[JF[A15]]
    lazy val a16Format = implicitly[JF[A16]]
    lazy val a17Format = implicitly[JF[A17]]
    lazy val a18Format = implicitly[JF[A18]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
        case x if implicitly[ClassTag[A11]].runtimeClass == x.getClass => a11Format.write(x.asInstanceOf[A11], builder)
        case x if implicitly[ClassTag[A12]].runtimeClass == x.getClass => a12Format.write(x.asInstanceOf[A12], builder)
        case x if implicitly[ClassTag[A13]].runtimeClass == x.getClass => a13Format.write(x.asInstanceOf[A13], builder)
        case x if implicitly[ClassTag[A14]].runtimeClass == x.getClass => a14Format.write(x.asInstanceOf[A14], builder)
        case x if implicitly[ClassTag[A15]].runtimeClass == x.getClass => a15Format.write(x.asInstanceOf[A15], builder)
        case x if implicitly[ClassTag[A16]].runtimeClass == x.getClass => a16Format.write(x.asInstanceOf[A16], builder)
        case x if implicitly[ClassTag[A17]].runtimeClass == x.getClass => a17Format.write(x.asInstanceOf[A17], builder)
        case x if implicitly[ClassTag[A18]].runtimeClass == x.getClass => a18Format.write(x.asInstanceOf[A18], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A11]].runtimeClass) == x => a11Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A12]].runtimeClass) == x => a12Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A13]].runtimeClass) == x => a13Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A14]].runtimeClass) == x => a14Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A15]].runtimeClass) == x => a15Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A16]].runtimeClass) == x => a16Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A17]].runtimeClass) == x => a17Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A18]].runtimeClass) == x => a18Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10,  A11,  A12,  A13,  A14,  A15,  A16,  A17,  A18,  A19 must be a concrete leaf type, and not an interface. */
  def unionFormat19[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag, A11 :JF: ClassTag, A12 :JF: ClassTag, A13 :JF: ClassTag, A14 :JF: ClassTag, A15 :JF: ClassTag, A16 :JF: ClassTag, A17 :JF: ClassTag, A18 :JF: ClassTag, A19 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]
    lazy val a11Format = implicitly[JF[A11]]
    lazy val a12Format = implicitly[JF[A12]]
    lazy val a13Format = implicitly[JF[A13]]
    lazy val a14Format = implicitly[JF[A14]]
    lazy val a15Format = implicitly[JF[A15]]
    lazy val a16Format = implicitly[JF[A16]]
    lazy val a17Format = implicitly[JF[A17]]
    lazy val a18Format = implicitly[JF[A18]]
    lazy val a19Format = implicitly[JF[A19]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
        case x if implicitly[ClassTag[A11]].runtimeClass == x.getClass => a11Format.write(x.asInstanceOf[A11], builder)
        case x if implicitly[ClassTag[A12]].runtimeClass == x.getClass => a12Format.write(x.asInstanceOf[A12], builder)
        case x if implicitly[ClassTag[A13]].runtimeClass == x.getClass => a13Format.write(x.asInstanceOf[A13], builder)
        case x if implicitly[ClassTag[A14]].runtimeClass == x.getClass => a14Format.write(x.asInstanceOf[A14], builder)
        case x if implicitly[ClassTag[A15]].runtimeClass == x.getClass => a15Format.write(x.asInstanceOf[A15], builder)
        case x if implicitly[ClassTag[A16]].runtimeClass == x.getClass => a16Format.write(x.asInstanceOf[A16], builder)
        case x if implicitly[ClassTag[A17]].runtimeClass == x.getClass => a17Format.write(x.asInstanceOf[A17], builder)
        case x if implicitly[ClassTag[A18]].runtimeClass == x.getClass => a18Format.write(x.asInstanceOf[A18], builder)
        case x if implicitly[ClassTag[A19]].runtimeClass == x.getClass => a19Format.write(x.asInstanceOf[A19], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A11]].runtimeClass) == x => a11Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A12]].runtimeClass) == x => a12Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A13]].runtimeClass) == x => a13Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A14]].runtimeClass) == x => a14Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A15]].runtimeClass) == x => a15Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A16]].runtimeClass) == x => a16Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A17]].runtimeClass) == x => a17Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A18]].runtimeClass) == x => a18Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A19]].runtimeClass) == x => a19Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10,  A11,  A12,  A13,  A14,  A15,  A16,  A17,  A18,  A19,  A20 must be a concrete leaf type, and not an interface. */
  def unionFormat20[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag, A11 :JF: ClassTag, A12 :JF: ClassTag, A13 :JF: ClassTag, A14 :JF: ClassTag, A15 :JF: ClassTag, A16 :JF: ClassTag, A17 :JF: ClassTag, A18 :JF: ClassTag, A19 :JF: ClassTag, A20 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]
    lazy val a11Format = implicitly[JF[A11]]
    lazy val a12Format = implicitly[JF[A12]]
    lazy val a13Format = implicitly[JF[A13]]
    lazy val a14Format = implicitly[JF[A14]]
    lazy val a15Format = implicitly[JF[A15]]
    lazy val a16Format = implicitly[JF[A16]]
    lazy val a17Format = implicitly[JF[A17]]
    lazy val a18Format = implicitly[JF[A18]]
    lazy val a19Format = implicitly[JF[A19]]
    lazy val a20Format = implicitly[JF[A20]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
        case x if implicitly[ClassTag[A11]].runtimeClass == x.getClass => a11Format.write(x.asInstanceOf[A11], builder)
        case x if implicitly[ClassTag[A12]].runtimeClass == x.getClass => a12Format.write(x.asInstanceOf[A12], builder)
        case x if implicitly[ClassTag[A13]].runtimeClass == x.getClass => a13Format.write(x.asInstanceOf[A13], builder)
        case x if implicitly[ClassTag[A14]].runtimeClass == x.getClass => a14Format.write(x.asInstanceOf[A14], builder)
        case x if implicitly[ClassTag[A15]].runtimeClass == x.getClass => a15Format.write(x.asInstanceOf[A15], builder)
        case x if implicitly[ClassTag[A16]].runtimeClass == x.getClass => a16Format.write(x.asInstanceOf[A16], builder)
        case x if implicitly[ClassTag[A17]].runtimeClass == x.getClass => a17Format.write(x.asInstanceOf[A17], builder)
        case x if implicitly[ClassTag[A18]].runtimeClass == x.getClass => a18Format.write(x.asInstanceOf[A18], builder)
        case x if implicitly[ClassTag[A19]].runtimeClass == x.getClass => a19Format.write(x.asInstanceOf[A19], builder)
        case x if implicitly[ClassTag[A20]].runtimeClass == x.getClass => a20Format.write(x.asInstanceOf[A20], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A11]].runtimeClass) == x => a11Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A12]].runtimeClass) == x => a12Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A13]].runtimeClass) == x => a13Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A14]].runtimeClass) == x => a14Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A15]].runtimeClass) == x => a15Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A16]].runtimeClass) == x => a16Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A17]].runtimeClass) == x => a17Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A18]].runtimeClass) == x => a18Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A19]].runtimeClass) == x => a19Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A20]].runtimeClass) == x => a20Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10,  A11,  A12,  A13,  A14,  A15,  A16,  A17,  A18,  A19,  A20,  A21 must be a concrete leaf type, and not an interface. */
  def unionFormat21[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag, A11 :JF: ClassTag, A12 :JF: ClassTag, A13 :JF: ClassTag, A14 :JF: ClassTag, A15 :JF: ClassTag, A16 :JF: ClassTag, A17 :JF: ClassTag, A18 :JF: ClassTag, A19 :JF: ClassTag, A20 :JF: ClassTag, A21 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]
    lazy val a11Format = implicitly[JF[A11]]
    lazy val a12Format = implicitly[JF[A12]]
    lazy val a13Format = implicitly[JF[A13]]
    lazy val a14Format = implicitly[JF[A14]]
    lazy val a15Format = implicitly[JF[A15]]
    lazy val a16Format = implicitly[JF[A16]]
    lazy val a17Format = implicitly[JF[A17]]
    lazy val a18Format = implicitly[JF[A18]]
    lazy val a19Format = implicitly[JF[A19]]
    lazy val a20Format = implicitly[JF[A20]]
    lazy val a21Format = implicitly[JF[A21]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
        case x if implicitly[ClassTag[A11]].runtimeClass == x.getClass => a11Format.write(x.asInstanceOf[A11], builder)
        case x if implicitly[ClassTag[A12]].runtimeClass == x.getClass => a12Format.write(x.asInstanceOf[A12], builder)
        case x if implicitly[ClassTag[A13]].runtimeClass == x.getClass => a13Format.write(x.asInstanceOf[A13], builder)
        case x if implicitly[ClassTag[A14]].runtimeClass == x.getClass => a14Format.write(x.asInstanceOf[A14], builder)
        case x if implicitly[ClassTag[A15]].runtimeClass == x.getClass => a15Format.write(x.asInstanceOf[A15], builder)
        case x if implicitly[ClassTag[A16]].runtimeClass == x.getClass => a16Format.write(x.asInstanceOf[A16], builder)
        case x if implicitly[ClassTag[A17]].runtimeClass == x.getClass => a17Format.write(x.asInstanceOf[A17], builder)
        case x if implicitly[ClassTag[A18]].runtimeClass == x.getClass => a18Format.write(x.asInstanceOf[A18], builder)
        case x if implicitly[ClassTag[A19]].runtimeClass == x.getClass => a19Format.write(x.asInstanceOf[A19], builder)
        case x if implicitly[ClassTag[A20]].runtimeClass == x.getClass => a20Format.write(x.asInstanceOf[A20], builder)
        case x if implicitly[ClassTag[A21]].runtimeClass == x.getClass => a21Format.write(x.asInstanceOf[A21], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A11]].runtimeClass) == x => a11Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A12]].runtimeClass) == x => a12Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A13]].runtimeClass) == x => a13Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A14]].runtimeClass) == x => a14Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A15]].runtimeClass) == x => a15Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A16]].runtimeClass) == x => a16Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A17]].runtimeClass) == x => a17Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A18]].runtimeClass) == x => a18Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A19]].runtimeClass) == x => a19Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A20]].runtimeClass) == x => a20Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A21]].runtimeClass) == x => a21Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }
  /** *BEWARE*:  A1,  A2,  A3,  A4,  A5,  A6,  A7,  A8,  A9,  A10,  A11,  A12,  A13,  A14,  A15,  A16,  A17,  A18,  A19,  A20,  A21,  A22 must be a concrete leaf type, and not an interface. */
  def unionFormat22[U, A1 :JF: ClassTag, A2 :JF: ClassTag, A3 :JF: ClassTag, A4 :JF: ClassTag, A5 :JF: ClassTag, A6 :JF: ClassTag, A7 :JF: ClassTag, A8 :JF: ClassTag, A9 :JF: ClassTag, A10 :JF: ClassTag, A11 :JF: ClassTag, A12 :JF: ClassTag, A13 :JF: ClassTag, A14 :JF: ClassTag, A15 :JF: ClassTag, A16 :JF: ClassTag, A17 :JF: ClassTag, A18 :JF: ClassTag, A19 :JF: ClassTag, A20 :JF: ClassTag, A21 :JF: ClassTag, A22 :JF: ClassTag]: JF[U] = new JF[U] {
    lazy val a1Format = implicitly[JF[A1]]
    lazy val a2Format = implicitly[JF[A2]]
    lazy val a3Format = implicitly[JF[A3]]
    lazy val a4Format = implicitly[JF[A4]]
    lazy val a5Format = implicitly[JF[A5]]
    lazy val a6Format = implicitly[JF[A6]]
    lazy val a7Format = implicitly[JF[A7]]
    lazy val a8Format = implicitly[JF[A8]]
    lazy val a9Format = implicitly[JF[A9]]
    lazy val a10Format = implicitly[JF[A10]]
    lazy val a11Format = implicitly[JF[A11]]
    lazy val a12Format = implicitly[JF[A12]]
    lazy val a13Format = implicitly[JF[A13]]
    lazy val a14Format = implicitly[JF[A14]]
    lazy val a15Format = implicitly[JF[A15]]
    lazy val a16Format = implicitly[JF[A16]]
    lazy val a17Format = implicitly[JF[A17]]
    lazy val a18Format = implicitly[JF[A18]]
    lazy val a19Format = implicitly[JF[A19]]
    lazy val a20Format = implicitly[JF[A20]]
    lazy val a21Format = implicitly[JF[A21]]
    lazy val a22Format = implicitly[JF[A22]]

    def write[J](u: U, builder: Builder[J]): Unit = {
      builder.beginObject()
      builder.addFieldName("value")
      u match {
        case x if implicitly[ClassTag[A1]].runtimeClass == x.getClass => a1Format.write(x.asInstanceOf[A1], builder)
        case x if implicitly[ClassTag[A2]].runtimeClass == x.getClass => a2Format.write(x.asInstanceOf[A2], builder)
        case x if implicitly[ClassTag[A3]].runtimeClass == x.getClass => a3Format.write(x.asInstanceOf[A3], builder)
        case x if implicitly[ClassTag[A4]].runtimeClass == x.getClass => a4Format.write(x.asInstanceOf[A4], builder)
        case x if implicitly[ClassTag[A5]].runtimeClass == x.getClass => a5Format.write(x.asInstanceOf[A5], builder)
        case x if implicitly[ClassTag[A6]].runtimeClass == x.getClass => a6Format.write(x.asInstanceOf[A6], builder)
        case x if implicitly[ClassTag[A7]].runtimeClass == x.getClass => a7Format.write(x.asInstanceOf[A7], builder)
        case x if implicitly[ClassTag[A8]].runtimeClass == x.getClass => a8Format.write(x.asInstanceOf[A8], builder)
        case x if implicitly[ClassTag[A9]].runtimeClass == x.getClass => a9Format.write(x.asInstanceOf[A9], builder)
        case x if implicitly[ClassTag[A10]].runtimeClass == x.getClass => a10Format.write(x.asInstanceOf[A10], builder)
        case x if implicitly[ClassTag[A11]].runtimeClass == x.getClass => a11Format.write(x.asInstanceOf[A11], builder)
        case x if implicitly[ClassTag[A12]].runtimeClass == x.getClass => a12Format.write(x.asInstanceOf[A12], builder)
        case x if implicitly[ClassTag[A13]].runtimeClass == x.getClass => a13Format.write(x.asInstanceOf[A13], builder)
        case x if implicitly[ClassTag[A14]].runtimeClass == x.getClass => a14Format.write(x.asInstanceOf[A14], builder)
        case x if implicitly[ClassTag[A15]].runtimeClass == x.getClass => a15Format.write(x.asInstanceOf[A15], builder)
        case x if implicitly[ClassTag[A16]].runtimeClass == x.getClass => a16Format.write(x.asInstanceOf[A16], builder)
        case x if implicitly[ClassTag[A17]].runtimeClass == x.getClass => a17Format.write(x.asInstanceOf[A17], builder)
        case x if implicitly[ClassTag[A18]].runtimeClass == x.getClass => a18Format.write(x.asInstanceOf[A18], builder)
        case x if implicitly[ClassTag[A19]].runtimeClass == x.getClass => a19Format.write(x.asInstanceOf[A19], builder)
        case x if implicitly[ClassTag[A20]].runtimeClass == x.getClass => a20Format.write(x.asInstanceOf[A20], builder)
        case x if implicitly[ClassTag[A21]].runtimeClass == x.getClass => a21Format.write(x.asInstanceOf[A21], builder)
        case x if implicitly[ClassTag[A22]].runtimeClass == x.getClass => a22Format.write(x.asInstanceOf[A22], builder)
      }
      builder.addFieldName("type")
      builder.writeString(className(u.getClass))
      builder.endObject()
    }
    def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): U =
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val typeName = unbuilder.lookupField("type") match {
            case Some(x) => unbuilder.readString(x)
            case None    => deserializationError("Field not found: $type")
          }
          val valueJs = unbuilder.lookupField("value") match {
            case Some(x) => x
            case None    => deserializationError("Field not found: value")
          }
          val value = typeName match {
            case x if className(implicitly[ClassTag[A1]].runtimeClass) == x => a1Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A2]].runtimeClass) == x => a2Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A3]].runtimeClass) == x => a3Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A4]].runtimeClass) == x => a4Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A5]].runtimeClass) == x => a5Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A6]].runtimeClass) == x => a6Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A7]].runtimeClass) == x => a7Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A8]].runtimeClass) == x => a8Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A9]].runtimeClass) == x => a9Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A10]].runtimeClass) == x => a10Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A11]].runtimeClass) == x => a11Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A12]].runtimeClass) == x => a12Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A13]].runtimeClass) == x => a13Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A14]].runtimeClass) == x => a14Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A15]].runtimeClass) == x => a15Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A16]].runtimeClass) == x => a16Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A17]].runtimeClass) == x => a17Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A18]].runtimeClass) == x => a18Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A19]].runtimeClass) == x => a19Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A20]].runtimeClass) == x => a20Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A21]].runtimeClass) == x => a21Format.read(Some(valueJs), unbuilder)
            case x if className(implicitly[ClassTag[A22]].runtimeClass) == x => a22Format.read(Some(valueJs), unbuilder)
          }
          unbuilder.endObject()
          value match { case u: U @unchecked => u }
        case None => deserializationError("Expected union JsObject, but got None")
      }
  }

  private def className[A](c: Class[A]): String =
    try {
      c.getSimpleName
    } catch {
      case e: InternalError => c.getName
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy