This is TLDR; article.
If you are beginner to Scala-Circe library and you want to know how to decode/encode JSON, do as below.
Your Classes
Assume your application has a nested class named Person
which has members as classes.
Your Task
You need to encode objects and decode text using Circe and use them as per Business Logic.
How to do?
(I will give you a simple straight forward approach that will work for 95% use cases)
- Add implicit codec in companion objects for your case classes.
- Add encode and decode method in companion object.
That’s it you can use Person.encode
and Person.decode
methods.
Sample app is below.
If you want to access runnable version of this code, along with imports and library version, use below link.