com.rojoma.json.v3.util
Specifies that the base codec should add (and possibly remove) an extra field to the objects generated by the subclasses' com.rojoma.json.v3.codec.JsonEncodes and com.rojoma.json.v3.codec.JsonDecodes (and they must be objects).
abstract class Base case class SubclassA(name: String) extends Base case class SubclassB(x: Int, y: Int) extends Base implicit val aCodec = SimpleJsonCodecBuilder[SubclassA].build("name", _.name) implicit val bCodec = SimpleJsonCodecBuilder[SubclassB].build("x", _.x, "y", _.y) val baseCodec = SimpleHierarchyCodecBuilder[Base](InternalTag("type")). branch[SubclassA]("a"). branch[SubclassB]("b"). build println(baseCodec.encode(SubclassA("John"))) // { "type" : "a", "name" : "John" } println(baseCodec.encode(SubclassB(1, 2))) // { "type" : "b", "x" : 1, "y" : 2 }
Specifies that the base codec should add (and possibly remove) an extra field to the objects generated by the subclasses' com.rojoma.json.v3.codec.JsonEncodes and com.rojoma.json.v3.codec.JsonDecodes (and they must be objects).