Skip to content

Commit

Permalink
2.10 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Joni Freeman committed Aug 2, 2012
1 parent 8b1c891 commit b4c5345
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion core/json/src/main/scala/net/liftweb/json/Extraction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
2 changes: 1 addition & 1 deletion core/json/src/main/scala/net/liftweb/json/Formats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) {
Expand Down

0 comments on commit b4c5345

Please sign in to comment.