0

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.

ericky
  • 1,641
  • 2
  • 14
  • 16
  • how would you expect to be represented? Also have you checked [Helios]?(https://github.com/47deg/helios) – LordRaydenMK Oct 22 '19 at 18:55
  • I checked Helios before posting the question. I saw no discussion or example of encoding/decoding an `Option` datatype. – ericky Oct 22 '19 at 19:10

0 Answers0