-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Labels
enhancementNew feature or requestNew feature or request
Description
While the default mechanism of including a discriminator allows for easy parsing, sometimes there is a need to match a specific JSON schema that doesn't include a single field that can be used for this purpose.
We should add an annotation that can be used on the trait that indicates that no discriminator will be present, and still allow generating a From
on the trait, and both From
and To
on the leaf classes. Only macroTo on the base class(es) should fail. Users can then either hand-code a To
, or omit it if it is not needed.
@nodiscriminator
sealed trait Fruit
case class Apple(seeds: Int) extends Fruit
implicit val fruitPickler: From[Fruit] = macroFrom
implicit val applePickler: FromTo[Apple] = macroFromTo
val red: Fruit = Apple(15)
val json = FromScala(red).transform(ToJson.string) // """{"seeds":15}"""
val reread = FromJson(json).transform(ToScala[Apple]) // Apple(15)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request