Writing non trivial Scala domain model as Json using Play framework
16 Aug 2015
Given the following domain model, implement the required Writers to convert instances to Json.
The standard writer incantation
implicit val mode = Json.writes[Mode]
fails when applied to the Mode trait because there is no unapply function.
This can be resolved by placing the following function in scope and deriving Mode from ObjectMarker.
The need to modify the domain model is suboptimal, but fortunately has no real consequence.
The object instance is represented by its class name, excluding the package(s) prefix and the trailing $.
The class instances of Configure are written as a Json object,
tagged by the class name (excluding package(s) prefix).
The object instances of Configure follow the same representation used for the enum as trait+object
pattern above.
The above code can probably be generated by a macro, but that effort is not yet justified.