Domanda

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.

È stato utile?

Soluzione

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

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top