Skip to content

Commit

Permalink
Add Seq support
Browse files Browse the repository at this point in the history
  • Loading branch information
Joni Freeman committed Apr 16, 2011
1 parent 02f1280 commit 18ddfdd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/json/README.md
Expand Up @@ -508,7 +508,7 @@ Serialization supports:

* Arbitrarily deep case class graphs
* All primitive types, including BigInt and Symbol
* List, Array, Set and Map (note, keys of the Map must be strings: Map[String, _])
* List, Seq, Array, Set and Map (note, keys of the Map must be strings: Map[String, _])
* scala.Option
* java.util.Date
* Polymorphic Lists (see below)
Expand Down
4 changes: 2 additions & 2 deletions core/json/src/main/scala/net/liftweb/json/Meta.scala
Expand Up @@ -109,8 +109,6 @@ private[json] object Meta {

def fieldMapping(fType: Class[_], genType: Type): (Mapping, Boolean) = {
if (primitive_?(fType)) (Value(fType), false)
else if (classOf[List[_]].isAssignableFrom(fType))
(mkContainer(genType, `* -> *`, 0, Col.apply(classOf[List[_]], _)), false)
else if (classOf[Set[_]].isAssignableFrom(fType))
(mkContainer(genType, `* -> *`, 0, Col.apply(classOf[Set[_]], _)), false)
else if (fType.isArray)
Expand All @@ -119,6 +117,8 @@ private[json] object Meta {
(mkContainer(genType, `* -> *`, 0, identity _), true)
else if (classOf[Map[_, _]].isAssignableFrom(fType))
(mkContainer(genType, `(*,*) -> *`, 1, Dict.apply _), false)
else if (classOf[Seq[_]].isAssignableFrom(fType))
(mkContainer(genType, `* -> *`, 0, Col.apply(classOf[List[_]], _)), false)
else {
if (visited.contains(fType)) (Cycle(fType), false)
else (Constructor(TypeInfo(fType, parameterizedTypeOpt(genType)),
Expand Down
Expand Up @@ -95,6 +95,12 @@ object SerializationExamples extends Specification {
s.array.toList mustEqual unser.array.toList
}

"Seq serialization example" in {
val s = SeqContainer(List("foo", "bar"))
val ser = swrite(s)
read[SeqContainer](ser) mustEqual s
}

"None Option of tuple serialization example" in {
// This is a regression test case, failed in lift json
val s = OptionOfTupleOfDouble(None)
Expand Down Expand Up @@ -343,4 +349,6 @@ case class SetContainer(set: Set[String])

case class ArrayContainer(array: Array[String])

case class SeqContainer(seq: Seq[String])

case class OptionOfTupleOfDouble(position: Option[Tuple2[Double, Double]])

0 comments on commit 18ddfdd

Please sign in to comment.