Serializing Map[Not-String, _]

14 views
Skip to first unread message

Thom Goodsell

unread,
May 4, 2015, 11:35:12 AM5/4/15
to scala...@googlegroups.com
Hi, all;

Apologies if I've missed something related in the archives, but I couldn't find anything.

I'm trying to migrate a bunch of existing object to Mongo using Salat, and I several of them have Maps with object keys. Using spray-json I was able to get them to write by creating an intermediate serialization object where I changed every Map[K,V] to Set[(K,V)]. This feels like something I should be able to do global and semi-magical with scalat, but I can't figure out how. Is this possible, and if so, where should I be looking?

If it's not possible, is there a way for me to register custom object -> key string conversions for types? For example, I have a map with MeasurementPoint instances as the keys and every MeasurementPoint has a unique name. So, if I can hand salat a custom mapper to and from those keys, then that would also work.

Thanks in advance.

Thom

rose katherine toomey

unread,
May 4, 2015, 11:54:41 AM5/4/15
to scala...@googlegroups.com
Hi Thom,

Unfortunately it's not possible right now: the easiest workaround is to persist some iterable of objects and then have a lazy val conversion of that iterable to a map.

The other features are good but Salat doesn't do them right now.  There are custom converters in Salat but they're not applied: map keys are expected to be strings The End.  I'd be happy to consider map key conversion as a future feature although the semi-magic intermediate Seq <-> Map conversion might be more useful for general cases.

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/d/optout.

Thom Goodsell

unread,
May 4, 2015, 1:29:49 PM5/4/15
to scala...@googlegroups.com
Ok. Thanks, Rose.

Thom

Reply all
Reply to author
Forward
0 new messages