开发者

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.


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


Now Salat offers JSON functionality backed by lift-json, so you can avoid this Option[Set[A]] mess in the first place.

Salat's JSON transformation supports default args, all the Salat annotations, and custom date and ObjectId serialization.

See https://github.com/novus/salat/wiki/JSON

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜