Let me preface by saying I am new to working with json and serialization and such. I am trying to create some json from some case classes. Here is my code from a scala worksheet I'm playing with:
import net.liftweb.json.DefaultFormats
import net.liftweb.json.Serialization.write
implicit val formats = DefaultFormats
// DBObjectTypes is an enumeration not shown in this snippet.
def update(dbObject: DBObjectTypes, updatePair: Map[String, Any]): Unit = {
case class Query(objectType: String, id: String, version: Long)
case class Update($set: Map[String, Any])
case class QueryUpdate(query: Query, update: Update)
val queryUpdate = QueryUpdate(Query(dbObject.toString, "test", 1L), Update(updatePair))
val updateJson = write(queryUpdate)
println(updateJson)
}
// SRAsubmission is an enumeration not show in this code snippet
update(SRAsubmission, Map("Desc" -> "Foo"))
This results in the following JSON:
{"$outer":{},"query":{"$outer":{},"objectType":"SRAsubmission","id":"test","version":1},"update":{"$outer":{},"$set":{"Desc":"Foo"}}}
What I want is as follows:
{"query":{"objectType":"SRAsubmission","id":"test","version":1},"update":{"$set":{"Desc":"Foo"}}}
I don't understand why I get the $outer: {} json elements. I'm pretty sure this is probably something fundamental that I don't understand but was not able to find any answers on StackOverflow or Google. Thanks in advance for any help!