Permalink
Browse files

2.10 fixes

  • Loading branch information...
1 parent 8b1c891 commit b4c53458f860b808013ccfcf915be9be8de71f44 Joni Freeman committed Aug 2, 2012
View
2 core/json/src/main/scala/net/liftweb/json/Extraction.scala
@@ -79,7 +79,7 @@ object Extraction {
case x: JValue => x
case x if primitive_?(x.getClass) => primitive2jvalue(x)(formats)
case x: Map[_, _] => JObject((x map { case (k: String, v) => JField(k, decompose(v)) }).toList)
- case x: Collection[_] => JArray(x.toList map decompose)
+ case x: Seq[_] => JArray(x.toList map decompose)
case x if (x.getClass.isArray) => JArray(x.asInstanceOf[Array[_]].toList map decompose)
case x: Option[_] => x.flatMap[JValue] { y => Some(decompose(y)) }.getOrElse(JNothing)
case x =>
View
2 core/json/src/main/scala/net/liftweb/json/Formats.scala
@@ -167,7 +167,7 @@ trait TypeHints {
*/
def hintFor(clazz: Class[_]): String = components.filter(_.containsHint_?(clazz))
.map(th => (th.hintFor(clazz), th.classFor(th.hintFor(clazz)).getOrElse(error("hintFor/classFor not invertible for " + th))))
- .sort((x, y) => (delta(x._2, clazz) - delta(y._2, clazz)) < 0).head._1
+ .sortWith((x, y) => (delta(x._2, clazz) - delta(y._2, clazz)) < 0).head._1
def classFor(hint: String): Option[Class[_]] = {
def hasClass(h: TypeHints) =
View
2 core/json/src/test/scala/net/liftweb/json/JsonPrintingSpec.scala
@@ -36,7 +36,7 @@ object JsonPrintingSpec extends Specification with JValueGen with ScalaCheck {
check(forAll(rendering))
}
- private def parse(json: String) = scala.util.parsing.json.JSON.parse(json)
+ private def parse(json: String) = scala.util.parsing.json.JSON.parseFull(json).get
implicit def arbDoc: Arbitrary[Document] = Arbitrary(genJValue.map(render(_)))
}
View
30 core/json/src/test/scala/net/liftweb/json/SerializationExamples.scala
@@ -263,21 +263,6 @@ object CustomSerializerExamples extends Specification {
}
))
- class IndexedSeqSerializer extends Serializer[IndexedSeq[_]] {
- def deserialize(implicit format: Formats) = {
- case (TypeInfo(clazz, ptype), json) if classOf[IndexedSeq[_]].isAssignableFrom(clazz) => json match {
- case JArray(xs) =>
- val t = ptype.getOrElse(throw new MappingException("parameterized type not known"))
- xs.map(x => Extraction.extract(x, TypeInfo(t.getActualTypeArguments()(0).asInstanceOf[Class[_]], None))).toIndexedSeq
- case x => throw new MappingException("Can't convert " + x + " to IndexedSeq")
- }
- }
-
- def serialize(implicit format: Formats) = {
- case i: IndexedSeq[_] => JArray(i.map(Extraction.decompose).toList)
- }
- }
-
implicit val formats = Serialization.formats(NoTypeHints) +
new IntervalSerializer + new PatternSerializer + new DateSerializer + new IndexedSeqSerializer
@@ -304,6 +289,21 @@ object CustomSerializerExamples extends Specification {
read[Indexed](iser).xs.toList mustEqual List("a","b","c")
}
+class IndexedSeqSerializer extends Serializer[IndexedSeq[_]] {
+ def deserialize(implicit format: Formats) = {
+ case (TypeInfo(clazz, ptype), json) if classOf[IndexedSeq[_]].isAssignableFrom(clazz) => json match {
+ case JArray(xs) =>
+ val t = ptype.getOrElse(throw new MappingException("parameterized type not known"))
+ xs.map(x => Extraction.extract(x, TypeInfo(t.getActualTypeArguments()(0).asInstanceOf[Class[_]], None))).toIndexedSeq
+ case x => throw new MappingException("Can't convert " + x + " to IndexedSeq")
+ }
+ }
+
+ def serialize(implicit format: Formats) = {
+ case i: IndexedSeq[_] => JArray(i.map(Extraction.decompose).toList)
+ }
+}
+
case class Indexed(xs: IndexedSeq[String])
class Interval(start: Long, end: Long) {

0 comments on commit b4c5345

Please sign in to comment.