简体   繁体   中英

How to format a case class which its paramters is more than 22

well,I have looked over the playframework document about json transformers ,it worked well until my case class's parameters more than 22 . When the parameters of case class is more than 22,An error which tell me that the case class's unapplay function couldn't be found has occurred

First, if you have a case class with 22 fields, it is a sign of a incorrect bad. However, if you have no choice to refactor your code you can do the following:

for example here is my case class:

case class MyClass(arg1: String, arg2: String, arg3: String)

I can rewrite the above class with two fields as follows:

case class Helper(arg1: String, arg2: String)
case class MyClass(arg12: Helper, arg3: String)

So by factoring out the first two argument in a case class, MyClass will have two fields instead of three. Of course I demonstrated it just by three fields because demonstrating it with 22 fields is tedious ;).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM