Packages

class flatten extends Annotation with StaticAnnotation

Changes the serialization format used by GenCodecs automatically derived for sealed hierarchies. The format is changed from "nested" to "flat".

@flatten sealed trait Value
case class Numeric(int: Int) extends Value
case class Textual(string: String) extends Value
object Value {
  implicit val codec: GenCodec[Value] = GenCodec.materialize[Value]
}

Without flatten annotation, the "nested" format is used, e.g. when Numeric(42) would be encoded to JSON as:

{"Numeric": {"int": 42}}

but when flatten annotation is applied on sealed trait/class, then it changes to:

{"_case": "Numeric", "int": 42}

The "_case" field name can be customized with annotation parameter

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. flatten
  2. StaticAnnotation
  3. Annotation
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new flatten()
  2. new flatten(caseFieldName: String)

Value Members

  1. val caseFieldName: String