Cannot extract data from json with more than 22 fields in scala 2.10

934 views Asked by At

I am trying to extract values from the json dataset where each record has n > 22 key-value pairs. In order to do so, I implemented a case class with n member variables. However, the scala 2.10.x compiler reported "Implementation restriction: case classes cannot have more than 22 parameters."

It seems the problem come from the limitation of the scala compiler, but is there any detour to solve this problem?

UPDATE:

I tried to decompose the big case classes into smaller one (use nested case class), but the program cannot correctly parse the json in that case. I think the implementation of json4s does not allow us to do so.

1

There are 1 answers

0
Eugene Zhulenev On

1: Switch to scala 2.11

2: Use nested case classes. For example if you have big model for 'Person' class you can split it like this:

case class Details(firstName: String, lastName: String, ...)
case class Address(state: String, street: String, ...)
case class Person(details: Details, address: Address)