我想在Scala中解析Json,我正在使用Json4s。
case class Child(name: String, age: Int, birthdate: Option[java.util.Date])
case class Address(street: String, city: String)
case class Person(name: String, address: Address, children: List[Child])
val json = parse("""{ "name": "joe",
"address": {
"street": "Bulevard",
"city": "Helsinki"
},
"children": [
{
"name": "Mary",
"age": 5,
"birthdate": "2004-09-04T18:06:22Z"
},
{
"name": "Mazy",
"age": 3
}
]
}""")
val must_ = json.extract[Person]
这对我来说非常好。
现在,我在Java中使用Java类,地址,Child也使用getter和setter。我想重用它们而不是在Java中定义case类
我该怎么做?