objectTagToValue extends TagType with Product with Serializable
Specifies that the base codec should wrap the value generated by subclasses'
com.rojoma.json.codec.JsonCodecs in another object containing a single
field, which is the tag for that subclass.
Example:
abstractclass Base
caseclass SubclassA(name: String) extends Base
caseclass SubclassB(x: Int, y: Int) extends Base
implicitval aCodec = SimpleJsonCodecBuilder[SubclassA].build("name", _.name)
implicitval bCodec = SimpleJsonCodecBuilder[SubclassB].build("x", _.x, "y", _.y)
val baseCodec = SimpleHierarchyCodecBuilder[Base](TagToValue).
branch[SubclassA]("a").
branch[SubclassB]("b").
build
println(baseCodec.encode(SubclassA("John"))) // { "a" : { "name" : "John" } }
println(baseCodec.encode(SubclassB(1, 2))) // { "b" : { "x" : 1, "y" : 2 } }
Linear Supertypes
Serializable, Serializable, Product, Equals, TagType, AnyRef, Any
Specifies that the base codec should wrap the value generated by subclasses' com.rojoma.json.codec.JsonCodecs in another object containing a single field, which is the tag for that subclass.