Permalink
Browse files

Switch JSON AST from lift-json to JSON4S

  • Loading branch information...
rktoomey committed Oct 25, 2012
1 parent 6019246 commit 285b555dc1bb1eadebce13572d60de598cdd12b9
View
@@ -5,7 +5,7 @@ Salat is a simple serialization library for case classes.
Salat currently supports bidirectional serialization for:
- MongoDB's `DBObject` (using [casbah][casbah])
-- JSON (using [lift-json][lift-json])
+- JSON (using [JSON4S][JSON4S])
- maps
# Goals
@@ -85,7 +85,7 @@ Details are thin on the ground, but here's where we got started:
[types]: https://github.com/novus/salat/wiki/SupportedTypes
[wiki]: https://github.com/novus/salat/wiki
[casbah]: https://github.com/mongodb/casbah/
-[lift-json]: https://github.com/lift/lift/tree/master/framework/lift-base/lift-json/
+[JSON4S]: http://json4s.org/
[group]: http://groups.google.com/group/scala-salat
[play-salat]: https://github.com/novus/salat/wiki/SalatWithPlay2
[play-salat-plugin]: https://github.com/leon/play-salat
View
@@ -1,3 +1,8 @@
Features new in Salat 1.9.2 include:
-- watch here
+- serialize case objects as strings (backwards compatible with old type hint serialization)
+- switched from lift-json to [JSON4S][JSON4S]
+- various fixes for JSON conversion, including an `Option` that contains a case object
+- support for converting `Map[String, _]` to compact rendered JSON
+
+[JSON4S]: http://json4s.org/
View
@@ -3,7 +3,7 @@ Salat is a simple serialization library for case classes.
Salat currently supports bidirectional serialization for:
- MongoDB's `DBObject` (using [casbah][casbah])
-- JSON (using [lift-json][lift-json])
+- JSON (using [JSON4S][JSON4S])
- maps
Find us online:
@@ -18,7 +18,7 @@ Find us online:
Salat is an Open Source project under the Apache License v2.
[casbah]: https://github.com/mongodb/casbah/
-[lift-json]: https://github.com/lift/lift/tree/master/framework/lift-base/lift-json/
+[JSON4S]: http://json4s.org/
[project]: http://novus.github.com/salat
[source]: https://github.com/novus/salat
[wiki]: https://github.com/novus/salat/wiki
View
@@ -33,7 +33,7 @@ object SalatBuild extends Build {
val testDeps = Seq(specs2, logbackCore, logbackClassic)
val utilDeps = Seq(slf4jApi) ++ testDeps
- val coreDeps = Seq(casbah, lift_json, commonsLang) ++ testDeps
+ val coreDeps = Seq(casbah, json4sNative, commonsLang) ++ testDeps
lazy val salat = Project(
id = "salat",
@@ -70,7 +70,7 @@ object BuildSettings {
val buildVersion = "1.9.2-SNAPSHOT"
val buildScalaVersion = "2.9.2"
- val buildSettings = Defaults.defaultSettings ++ Format.settings ++ Publish.settings ++ Ls.settings ++ Seq(
+ val buildSettings = Defaults.defaultSettings ++ Format.settings ++ Publish.settings ++ Ls.settings ++ net.virtualvoid.sbt.graph.Plugin.graphSettings ++ Seq(
organization := buildOrganization,
version := buildVersion,
scalaVersion := buildScalaVersion,
@@ -146,13 +146,13 @@ object Dependencies {
private val LogbackVersion = "1.0.7"
- val specs2 = "org.specs2" %% "specs2" % "1.12.1" % "test"
+ val specs2 = "org.specs2" %% "specs2" % "1.12.2" % "test"
val commonsLang = "commons-lang" % "commons-lang" % "2.5" % "test"
val slf4jApi = "org.slf4j" % "slf4j-api" % "1.6.4"
val logbackCore = "ch.qos.logback" % "logback-core" % LogbackVersion % "test"
val logbackClassic = "ch.qos.logback" % "logback-classic" % LogbackVersion % "test"
val casbah = "org.mongodb" %% "casbah" % "2.4.1" pomOnly()
- val lift_json = "net.liftweb" %% "lift-json" % "2.5-M1"
+ val json4sNative = "org.json4s" %% "json4s-native" % "3.0.0"
}
object Repos {
View
@@ -9,3 +9,5 @@ addSbtPlugin("com.jsuereth" % "xsbt-gpg-plugin" % "0.6")
addSbtPlugin("me.lessis" % "ls-sbt" % "0.1.2")
+addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.0")
+
@@ -34,8 +34,8 @@ import com.novus.salat.annotations.util._
import java.lang.reflect.Modifier
import com.mongodb.casbah.Imports._
import java.util.concurrent.ConcurrentHashMap
-import net.liftweb.json._
import com.novus.salat.json.JSONConfig
+import org.json4s.JsonAST.JObject
trait Context extends ContextLifecycle with Logging {
@@ -35,8 +35,10 @@ import com.novus.salat.util._
import com.mongodb.casbah.Imports._
import com.novus.salat.util.Logging
-import net.liftweb.json._
+import org.json4s._
+import org.json4s.native.JsonMethods._
import com.novus.salat.json.{ FromJValue, ToJField }
+import org.json4s.native.JsonParser
// TODO: create companion object to serve as factory for grater creation - there
// is not reason for this logic to be wodged in Context
@@ -299,7 +301,7 @@ abstract class ConcreteGrater[X <: CaseClass](clazz: Class[X])(implicit ctx: Con
}
def fromJSON(j: JObject) = {
- val values = j.obj.map(v => (v.name, v.value)).toMap
+ val values = j.obj.map(v => (v._1, v._2)).toMap
val args = indexedFields.map {
case field if field.ignore => safeDefault(field)
case field => {
@@ -26,7 +26,7 @@
package com.novus.salat
import com.mongodb.casbah.Imports._
-import net.liftweb.json._
+import org.json4s.JsonAST.JObject
class ProxyGrater[X <: AnyRef](clazz: Class[X])(implicit ctx: Context) extends Grater[X](clazz)(ctx) {
@@ -28,8 +28,7 @@ package com.novus.salat.dao
import com.mongodb.casbah.Imports._
import com.novus.salat._
import com.novus.salat.util.Logging
-import net.liftweb.json._
-import net.liftweb.json.JsonAST.JObject
+import org.json4s.JsonAST.{ JArray, JObject }
/** Play framework style model companion
* <p/>
@@ -29,8 +29,8 @@ import org.scala_tools.time.Imports._
import org.joda.time.DateTimeZone
import org.joda.time.format.{ DateTimeFormatter, ISODateTimeFormat }
import java.util.Date
-import org.scala_tools.time.Imports
-import net.liftweb.json.JsonAST._
+import org.json4s._
+import org.json4s.native.JsonMethods._
import org.bson.types.{ BSONTimestamp, ObjectId }
object JSONConfig {
@@ -25,7 +25,8 @@
package com.novus.salat.json
-import net.liftweb.json._
+import org.json4s._
+import org.json4s.native.JsonMethods._
import com.mongodb.casbah.Imports._
import org.joda.time.DateTime
import com.novus.salat.{ Field => SField, _ }
@@ -125,7 +126,7 @@ object FromJValue extends Logging {
}
case o: JObject if field.tf.isMap && childType.isEmpty => field.typeRefType match {
case IsMap(_, childType: TypeRefType) => {
- o.obj.map(v => (v.name, apply(Some(v.value), field, Some(childType)))).collect {
+ o.obj.map(v => (v._1, apply(Some(v._2), field, Some(childType)))).collect {
case (key, Some(value)) => key -> value
}.toMap
}
@@ -226,7 +226,7 @@ package object in extends Logging {
package in {
import java.lang.Integer
- import net.liftweb.json.JsonAST.JArray
+ import org.json4s.JsonAST.JArray
trait LongToInt extends Transformer {
self: Transformer =>
@@ -24,13 +24,13 @@
*/
package com.novus.salat.test
-import com.novus.salat.util.Logging
import com.mongodb.casbah.Imports._
import org.specs2.mutable._
import org.specs2.specification.{ Scope, Step }
import com.novus.salat.{ BigDecimalStrategy, Context }
+import com.mongodb.casbah.commons.test.CasbahMutableSpecification
-trait SalatSpec extends Specification with Logging {
+trait SalatSpec extends CasbahMutableSpecification {
override def is =
Step {
@@ -26,15 +26,12 @@
package com.novus.salat.test.dao
import com.novus.salat.test.global._
-import com.novus.salat.annotations._
import com.mongodb.casbah.Imports._
import org.scala_tools.time.Imports._
-import com.novus.salat.dao.ModelCompanion
import com.novus.salat.test._
import org.specs2.specification.Scope
import com.novus.salat.json.JSONConfig
-import net.liftweb.json._
-import scala.util.parsing.json.JSONArray
+import org.json4s.JsonAST._
class ModelCompanionSpec extends SalatSpec {
// which most specs can execute concurrently, this particular spec needs to execute sequentially to avoid mutating shared state,
@@ -75,9 +75,9 @@ class SalatDAOSpec extends SalatSpec {
// the standard collection cursor returns DBOs
val mongoCursor = AlphaDAO.collection.find()
- mongoCursor.next() must_== grater[Alpha].asDBObject(alpha4)
- mongoCursor.next() must_== grater[Alpha].asDBObject(alpha5)
- mongoCursor.next() must_== grater[Alpha].asDBObject(alpha6)
+ mongoCursor.next() must haveEntry("_id", alpha4.id)
+ mongoCursor.next() must haveEntry("_id", alpha5.id)
+ mongoCursor.next() must haveEntry("_id", alpha6.id)
// BUT the Salat DAO returns a cursor types to case classes!
val salatCursor = AlphaDAO.find(MongoDBObject.empty)
@@ -29,8 +29,8 @@ import org.specs2.mutable.Specification
import com.novus.salat.util.Logging
import org.joda.time.{ DateTimeZone, DateTime }
import com.novus.salat.json.StrictBSONTimestampStrategy
-import net.liftweb.json.JsonAST.{ JField, JObject, JInt, JString }
import org.bson.types.BSONTimestamp
+import org.json4s.JsonAST._
class BSONTimestampStrategySpec extends Specification with Logging {
@@ -29,8 +29,8 @@ import org.specs2.mutable.Specification
import com.novus.salat.util.Logging
import org.joda.time.{ DateTimeZone, DateTime }
import com.novus.salat.json.{ StrictJSONDateStrategy, TimestampDateStrategy, StringDateStrategy }
-import net.liftweb.json.JsonAST.{ JField, JObject, JInt, JString }
import org.joda.time.format.ISODateTimeFormat
+import org.json4s.JsonAST._
class DateStrategySpec extends Specification with Logging {
@@ -2,7 +2,6 @@ package com.novus.salat.test.json
import com.novus.salat.test.SalatSpec
import com.novus.salat.json.MapToJSON
-import net.liftweb.json._
class JsonMapSupport extends SalatSpec {
@@ -28,10 +28,9 @@ import com.novus.salat._
import com.novus.salat.util._
import json.{ StringDateStrategy, StrictJSONDateStrategy, TimestampDateStrategy, JSONConfig }
import org.specs2.mutable.Specification
-import net.liftweb.json._
import scala.util.parsing.json.{ JSONObject, JSONArray }
import org.bson.types.ObjectId
-import net.liftweb.json.JsonParser.ParseException
+import org.json4s._
import org.joda.time.{ DateTime, DateTimeZone }
import org.joda.time.DateTimeConstants._
import org.joda.time.format.ISODateTimeFormat
@@ -375,7 +374,7 @@ class JsonSpec extends Specification with Logging {
}
"throw an exception when string cannot be parsed to valid JSON" in {
val invalid = """?"""
- grater[Adam].fromJSON(invalid) must throwA[ParseException]
+ grater[Adam].fromJSON(invalid) must throwA[org.json4s.ParserUtil.ParseException]
}
"throw an exception when string parses to valid but unexpected JSON" in {
grater[Adam].fromJSON("""["a","b","c"]""") must throwA[RuntimeException]
@@ -29,7 +29,7 @@ import org.bson.types.ObjectId
import org.specs2.mutable.Specification
import com.novus.salat.util.Logging
import com.novus.salat.json.{ StrictJSONObjectIdStrategy, StringObjectIdStrategy }
-import net.liftweb.json.JsonAST.{ JField, JObject, JString }
+import org.json4s.JsonAST._
class ObjectIdSpec extends Specification with Logging {

0 comments on commit 285b555

Please sign in to comment.