Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Salat not deserializing collections that map to Option[Set[A]]

I asked this question in scala-salat Google group, but no response there for a few days, hence trying here.

I have a case class which has a collection wrapped in an Option.

case class SomeClass(
  var name:Option[String]=None,
  var addresses:Option[Set[Address]]=None
)

case class Address(
  var street:Option[String]=None,
  var zip:Option[String]=None
) 

The document gets stored in Mongo just fine. However, when I try to get this using findOne (with or without SalatDAO) the addresses field has JSON text representing addresses instead of the Address case class.

As a result, Lift-JSON skips any fields in my case class with Option[Collection[A]] in it. When I remove the Option and just go with addresses=Set[Address](), it works. However now I end up with empty sets in my JSON where there is no data, and I have no way to find out on an update if the consumer removed the entries, or I am getting an empty Set because the consumer did not send this field in the original request.

Using Option would have set the field to None, which would mean that I would not have to worry about it being empty or modified.

Any help will be greatly appreciated.

like image 859
lobster1234 Avatar asked Sep 17 '11 23:09

lobster1234


1 Answers

Sorry, Salat does not currently support an Option that contains a collection.

like image 93
prasinous Avatar answered Sep 23 '22 22:09

prasinous