diff --git a/core/json/README.md b/core/json/README.md index 7b8eda57e6..bb6c775666 100644 --- a/core/json/README.md +++ b/core/json/README.md @@ -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) diff --git a/core/json/src/main/scala/net/liftweb/json/Meta.scala b/core/json/src/main/scala/net/liftweb/json/Meta.scala index 1a851549d6..3759e4faa7 100644 --- a/core/json/src/main/scala/net/liftweb/json/Meta.scala +++ b/core/json/src/main/scala/net/liftweb/json/Meta.scala @@ -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) @@ -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)), diff --git a/core/json/src/test/scala/net/liftweb/json/SerializationExamples.scala b/core/json/src/test/scala/net/liftweb/json/SerializationExamples.scala index 7442b94da3..7040f218da 100644 --- a/core/json/src/test/scala/net/liftweb/json/SerializationExamples.scala +++ b/core/json/src/test/scala/net/liftweb/json/SerializationExamples.scala @@ -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) @@ -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]])