AdtEncodingStrategy

Companion:
class
class Object
trait Matchable
class Any

Type members

Classlikes

Default and recommended ADT encoding strategy. Encodes the ADT super type as a single-element map with the only member consisting of the type ID as key and the instance encoding as the value.

Default and recommended ADT encoding strategy. Encodes the ADT super type as a single-element map with the only member consisting of the type ID as key and the instance encoding as the value.

Example:

A Dog instance from this ADT:

 sealed trait Animal
 case class Dog(age: Int, name: String)                      extends Animal
 case class Cat(weight: Double, color: String, home: String) extends Animal
 case class Mouse(tail: Boolean)                             extends Animal

would be encoded as such, for example:

 {
   "Dog" :  {
     "age": 2,
     "name": "Lolle"
    }
 }

Value members

Concrete methods

def flat(typeMemberName: String, maxBufferSize: Int): AdtEncodingStrategy

Alternative ADT encoding strategy, which writes the type ID as an extra map member. The extra member will be the first member in the encoding. (But can be anywhere during decoding. The earlier the type member appears in the encoding map the better the decoding performance and the lesser the caching memory requirements will be.)

Alternative ADT encoding strategy, which writes the type ID as an extra map member. The extra member will be the first member in the encoding. (But can be anywhere during decoding. The earlier the type member appears in the encoding map the better the decoding performance and the lesser the caching memory requirements will be.)

Requires that all ADT sub types encode to a map. Less efficient (with regard to encoding/decoding process as well as encoded size) than the default strategy.

Example:

A Dog instance from this ADT:

 sealed trait Animal
 case class Dog(age: Int, name: String)                      extends Animal
 case class Cat(weight: Double, color: String, home: String) extends Animal
 case class Mouse(tail: Boolean)                             extends Animal

would be encoded as such, for example:

 {
   "_type": "Dog",
   "age": 2,
   "name": "Lolle"
 }