Browse files

Memoization should not ingore type parameters. Fixes #1417.

  • Loading branch information...
1 parent c7615ec commit ba2c444076ee6f5dc788bcaab4853b1640b5fef1 Joni Freeman committed Mar 11, 2013
View
4 core/json/src/main/scala/net/liftweb/json/Meta.scala
@@ -80,7 +80,7 @@ private[json] object Meta {
// Current constructor parsing context. (containingClass + allArgs could be replaced with Constructor)
case class Context(argName: String, containingClass: Class[_], allArgs: List[(String, Type)])
- private val mappings = new Memo[Type, Mapping]
+ private val mappings = new Memo[(Type, Seq[Class[_]]), Mapping]
private val unmangledNames = new Memo[String, String]
private val paranamer = new CachingParanamer(new BytecodeReadingParanamer)
@@ -158,7 +158,7 @@ private[json] object Meta {
if (primitive_?(clazz)) Value(rawClassOf(clazz))
else {
- mappings.memoize(clazz, t => {
+ mappings.memoize((clazz, typeArgs), { case (t, _) =>
val c = rawClassOf(t)
val (pt, typeInfo) =
if (typeArgs.isEmpty) (t, TypeInfo(c, None))
View
11 core/json/src/test/scala/net/liftweb/json/SerializationBugs.scala
@@ -155,8 +155,19 @@ object SerializationBugs extends Specification {
val ser = swrite(MapHolder(Map("hello" -> SingleValue(2.0))))
read[MapHolder](ser) mustEqual MapHolder(Map("hello" -> SingleValue(2.0)))
}
+
+ "Constructor memoization should not ignore type parameters" in {
+ val jsonA = """ { "data": { "foo": "string" }, "success": true } """
+ read[SomeContainer[TypeA]](jsonA) mustEqual SomeContainer(TypeA("string"))
+ val jsonB = """ { "data": { "bar": "string" }, "success": true } """
+ read[SomeContainer[TypeB]](jsonB) mustEqual SomeContainer(TypeB("string"))
+ }
}
+case class TypeA(foo: String)
+case class TypeB(bar: String)
+case class SomeContainer[D](data: D)
+
case class Eith(x: Either[String, Int])
case class MapWithMap(a: Map[String, Map[String, Int]], b: Map[String, Int])

0 comments on commit ba2c444

Please sign in to comment.