Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

TypeInfo is correctly constructed for customer serializer, fixes 970

  • Loading branch information...
commit 7654ea031879956e35d30ed0fb29f5aa8c6ea61a 1 parent 18f9e9e
Joni Freeman authored
View
2  core/json/src/main/scala/net/liftweb/json/Extraction.scala
@@ -184,7 +184,7 @@ object Extraction {
Col(clazz, mappingOf(typeArgs(0)))
else if (clazz == classOf[Map[_, _]])
Dict(mappingOf(typeArgs(1)))
- else mappingOf(clazz)
+ else mappingOf(clazz, typeArgs)
extract0(json, mapping)
}
View
19 core/json/src/main/scala/net/liftweb/json/Meta.scala
@@ -82,7 +82,8 @@ private[json] object Meta {
paranamer.lookupParameterNames(constructor)
}
- private[json] def mappingOf(clazz: Class[_])(implicit formats: Formats): Mapping = {
+ private[json] def mappingOf(clazz: Class[_], typeArgs: Seq[Class[_]] = Seq())
+ (implicit formats: Formats): Mapping = {
import Reflection._
def constructors(clazz: Class[_], visited: Set[Class[_]]) =
@@ -127,9 +128,23 @@ private[json] object Meta {
}
if (primitive_?(clazz)) Value(clazz)
- else mappings.memoize(clazz, c => Constructor(TypeInfo(c, None), constructors(c, Set())))
+ else {
+ mappings.memoize(clazz, c => {
+ val typeInfo =
+ if (typeArgs.isEmpty) TypeInfo(c, None)
+ else TypeInfo(c, Some(mkParameterizedType(c, typeArgs)))
+ Constructor(typeInfo, constructors(c, Set()))
+ })
+ }
}
+ private[json] def mkParameterizedType(owner: Class[_], typeArgs: Seq[Class[_]]) =
+ new ParameterizedType {
+ def getActualTypeArguments = typeArgs.toArray
+ def getOwnerType = owner
+ def getRawType = owner
+ }
+
private[json] def unmangleName(name: String) =
unmangledNames.memoize(name, operators.foldLeft(_)((n, o) => n.replace(o._1, o._2)))
View
24 core/json/src/test/scala/net/liftweb/json/SerializationBugs.scala
@@ -87,6 +87,30 @@ object SerializationBugs extends Specification {
read[OptionalUUID](swrite(o1)) mustEqual o1
read[OptionalUUID](swrite(o2)) mustEqual o2
}
+
+ "TypeInfo is not correctly constructed for customer serializer -- 970" in {
+ class SeqFormat extends Serializer[Seq[_]] {
+ val SeqClass = classOf[Seq[_]]
+
+ def serialize(implicit format: Formats) = {
+ case seq: Seq[_] => JArray(seq.toList.map(Extraction.decompose))
+ }
+
+ def deserialize(implicit format: Formats) = {
+ case (TypeInfo(SeqClass, parameterizedType), JArray(xs)) =>
+ val typeInfo = TypeInfo(parameterizedType
+ .map(_.getActualTypeArguments()(0))
+ .getOrElse(fail("No type parameter info for type Seq")).asInstanceOf[Class[_]], None)
+ xs.map(x => Extraction.extract(x, typeInfo))
+ }
+ }
+
+ implicit val formats = DefaultFormats + new SeqFormat
+
+ val seq = Seq(1, 2, 3)
+ val ser = Extraction.decompose(seq)
+ Extraction.extract[Seq[Int]](ser) mustEqual seq
+ }
}
case class LongList(xs: List[Num])
Please sign in to comment.
Something went wrong with that request. Please try again.