Example:
opaque type UserName = String
This version is serialized automatically:
case class UserName(value: String) extends AnyVal
Example:
opaque type UserName = String
This version is serialized automatically:
case class UserName(value: String) extends AnyVal
2
Answers
I don't know if it is the most elegant way of doing it, because I'm novice in
circe
:The easiest way is to NOT use raw
opaque type
:The mechanism for all of them is the same:
it’s just the common content is extracted into a mixin trait
which would provide some instance of
ConvertToAndFrom[Inner, Outer]
(sometimes split into 2 type classes, 1 for extraction and 1 for construction, details depends on the library).It saves unnecessary burden of writing something like: