[play 2.4] Json Reads/Writes with more than 22 parameters

2,351 views
Skip to first unread message

valtteri...@hotmail.com

unread,
Sep 10, 2015, 9:54:29 AM9/10/15
to play-framework
Hi!

One of our case classes has 30 constructor parameters and we ran into a problem with Json Reads/Writes. They seem to be able to handle only 22 parameters. Beyond that, you get the error message "No unapply or unapplySeq function found".

I cut away some parameters into their own case class like this:

case class LotsOfParams(params....) -> case class NotSoManyParams(smallerCaseClass, other params....)

But this causes the Json to change form. Now we have:

{
  "smallerCaseClass": { cutParamsHere }
}

Which sucks because our client software is relying on the old format.

Can you suggest of alternative ways of handling the situation, or do I have to manually create a Writes with explicit instructions for all the 30 fields?

Valtteri

Mariot Chauvin

unread,
Sep 10, 2015, 10:11:35 AM9/10/15
to play-fr...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/65b86db5-957b-4875-91fd-bec02eae6c75%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



Visit theguardian.com. On your mobile and tablet, download the Guardian iPhone and Android apps theguardian.com/guardianapp and our tablet editions theguardian.com/editions.  Save up to 57% by subscribing to the Guardian and Observer - choose the papers you want and get full digital access.  Visit subscribe.theguardian.com

This e-mail and all attachments are confidential and may also be privileged. If you are not the named recipient, please notify the sender and delete the e-mail and all attachments immediately. Do not disclose the contents to another person. You may not use the information for any purpose, or store, or copy, it in any way.  Guardian News & Media Limited is not liable for any computer viruses or other material transmitted with or as part of this e-mail. You should employ virus checking software.
 
Guardian News & Media Limited is a member of Guardian Media Group plc. Registered Office: PO Box 68164, Kings Place, 90 York Way, London, N1P 2AP.  Registered in England Number 908396


Mariot Chauvin

unread,
Sep 10, 2015, 10:26:50 AM9/10/15
to play-fr...@googlegroups.com
As this is not pointed the stackoverflow response, you could also use https://github.com/jto/validation which does not 

valtteri...@hotmail.com

unread,
Sep 11, 2015, 3:34:10 AM9/11/15
to play-framework
Thank you for the suggestions!

I wonder if the Reads/Writes could be modified some day to use constructor fields instead of apply/unapply as well, like the validation macros. I haven't looked at how exactly the Reads/Writes are implemented now so that's just a though that came to mind.

Time to code now.. prototype towards the most elegant solution.. thanks again :)

Valtteri

valtteri...@hotmail.com

unread,
Sep 11, 2015, 4:04:06 AM9/11/15
to play-framework
You know, after thinking about this a bit, I thought I'd go with explicit instructions for all the 30 fields. It's only a single case class so I don't need a more generic way. So I thought it would be the simplest solution and also easiest to read for others.

But what happened? I can't use Writes because they rely on unapply. So I tried using a plain old Json.obj() - function to construct the Json. There's just a single caveat. Unlike Writes, Json.obj() writes Option None values as nulls. So I googled this and guess what the suggested solution is? To use Writes of course. Back to square one..

Valtteri
Reply all
Reply to author
Forward
0 new messages