Re: case class limit

93 views
Skip to first unread message

rktoomey

unread,
Nov 1, 2012, 12:50:16 PM11/1/12
to scala-salat
Hi,

Nope. You're limited to 22 parameters in a case class right now.

However, if you just want to turn a Map[String, Any] to JSON and you
don't care about being able to deserialize it back to a model object,
I just added that ability to 1.9.2-SNAPSHOT.

See MapToJSON
https://github.com/novus/salat/blob/master/salat-core/src/main/scala/com/novus/salat/json/ToJValue.scala

And a usage example in the specs here:
https://github.com/novus/salat/blob/master/salat-core/src/test/scala/com/novus/salat/test/json/JsonMapSupport.scala

You feed MapToJSON a Map[String, Any] and it gives you back a compact
rendered JSON string.

Best,
Rose

On Nov 1, 10:57 am, devmunky <devmu...@gmail.com> wrote:
> Hi There,
>
> First of all i'd like to say hello and forgive me for being a n00b at
> scala. Coming from a php/ruby background and trying to branch out :)
>
> Right - that's out of the way.
>
> Basically i'm trying to create a rest service which currently proxies the
> output from an external service, saves the results in mongo and provides a
> local interface for this info. I seem to have hit an issue with a case
> class parameter limit being 22 parameters max. Is there an alternative to
> using a case class for annotations in salat?
>
> Many thanks.

Marius Soutier

unread,
Nov 1, 2012, 4:52:18 PM11/1/12
to scala...@googlegroups.com
Our solution to this is to nest case classes which also helps to structure your data in a more logical way.

philip andrew

unread,
Nov 13, 2013, 2:52:36 AM11/13/13
to scala...@googlegroups.com, mps...@googlemail.com
How do I nest the case classes in a way that it still maps to a single table?

rose katherine toomey

unread,
Nov 13, 2013, 8:16:58 AM11/13/13
to scala-salat
Hi Philip,

Nested case classes will turn into embedded documents.  This works out rather well in most cases.

If you want to persist your nested case classes into separate collections, then see the wiki docs on using a child collection.  You can override the save method to break up your case object hierarchy and persist to parent and child collections, and then override the find method to retrieve children by parent id and stuff them back into the parent object when you retrieve.

If you want something that will flatten out your case class into a single level in a Mongo collection, I don't know of anything that does this.

Best,
Rose


--
You received this message because you are subscribed to the Google Groups "scala-salat" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-salat...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages