Koltin newbie here. If I have a library with (Kotlin) Borrowers and Books and a Book
is checked out when it has a Borrower
(using Arrow's Option
datatype):
data class Borrower(val name: Name, val maxBooks: MaxBooks)
data class Book(val title: Title, val author: Author, val maybeBorrower: Option<Borrower> = None)
How do I encode and decode between a tiny library:
val br1 = Borrower("Borrower1", 1)
val bk1 = Book("Title1", "Author1", Some(br1))
val bk2 = Book("Title2", "Author2", None)
And it's JSON representation:
val jsonStringBooks = """[{"title":"Title1","author":"Author1","borrower":{"name":"Borrower1","maxBooks":1}},{"title":"Title2","author":"Author2","borrower":null}]"""
Using Klaxon?
The representation of an Option
(or Either
?) through Klaxon is throwing me off. I believe Scala's spray-json handles these datatypes.
Thank you.