I have some case classes:
case class Address(street : String, state : String, zip : Option[Int])
case class Person(name : String, address : Option[Address], children : Seq[Person])
and a function that returns one of these classes:
def getPerson() : Person
I want to make a version of this function that can be called from Java:
def getPersonJava() : JavaPerson
where JavaPerson
would have the same fields as the case class but the Option
would be java 8 Optional
and the Seq
would be java.util.List
or some more suitable java collection type.
And when the user calls getPersonJava().address
they would get an instance of a class where the fields had also been transformed.
Is there a way to transform nested case classes like this using macros or something so that I don't have to manually write the conversions? I cannot change the case classes or the getPerson
function.