Last active
November 13, 2021 07:50
-
-
Save seeni-dev/dc854e25fbdc03047e1912273daae56a to your computer and use it in GitHub Desktop.
YourClassesWithCodec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.circe._, io.circe.generic.semiauto._, io.circe.syntax._ | |
case class Address(doorNo: Int, street: String, city: String, zipCode: String) | |
object Address { | |
implicit val codec = deriveCodec[Address] | |
} | |
case class Person(name: String, age: Int, address: Address) | |
object Person { | |
implicit val codec = deriveCodec[Person] | |
def encode(person: Person): String = { | |
person.asJson.toString | |
} | |
def decode(jsonString: String): Person = { | |
parser.decode[Person](jsonString).toOption.get | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment