Circe: decoding Json field with alias, how to do it?

Viewed 43

Assuming that I have a Scala case class that contains a field "someRandomName" that has an alias "someArbitraryName":

case class NN(
  name1: Option[String],
  @alias("someArbitraryName") someRandomName: String
 // ... 100 more optional fields
)

I need to derive a decoder semi-automatically that can parse both:

{"someRandomName" : "abc"}

and

{"someArbitraryName" : "abc"}

into the exact same instance of the class NN

What's the shortest way to do it in circe?

0 Answers
Related