Permalink
Browse files

Read erased type from ScalaSig

  • Loading branch information...
1 parent 299f2e1 commit 0e4cb6d70d01983ed2ec7227aad428897108cfeb Joni Freeman committed May 17, 2011
@@ -39,13 +39,11 @@ object JsonBoxSerializerSpec extends Specification("JsonBoxSerializer Specificat
parse("""{"name":"joe", "thing": "rog", "age":12}""").extract[Person] mustEqual Person("joe", Full(12), Empty, Full("rog"))
}
-
-
"Extract boxed mother" in {
val json = """{"name":"joe", "age":12, "mother": {"name":"ann", "age":53}}"""
val p = parse(json).extract[Person]
p mustEqual Person("joe", Full(12), Full(Person("ann", Full(53), Empty)))
- (for { a1 <- p.age; m <-p.mother; a2 <- m.age } yield a1+a2) mustEqual Some(65)
+ (for { a1 <- p.age; m <-p.mother; a2 <- m.age } yield a1+a2) mustEqual Full(65)
}
"Render with age" in {
@@ -70,5 +68,5 @@ object JsonBoxSerializerSpec extends Specification("JsonBoxSerializer Specificat
case class SomeException(msg: String) extends Exception
-case class Person(name: String, age: Option[Int], mother: Box[Person], thing: Box[String] = Empty)
+case class Person(name: String, age: Box[Int], mother: Box[Person], thing: Box[String] = Empty)
@@ -107,7 +107,14 @@ private[json] object Meta {
} else factory(fieldMapping(typeParameters(t, k, context)(valueTypeIndex))._1)
def parameterizedTypeOpt(t: Type) = t match {
- case x: ParameterizedType => Some(x)
+ case x: ParameterizedType =>
+ val typeArgs = x.getActualTypeArguments.toList.zipWithIndex
+ .map { case (t, idx) =>
+ if (t == classOf[java.lang.Object])
+ ScalaSigReader.readConstructor(context.argName, context.containingClass, context.allArgs.map(_._1))
+ else t
+ }
+ Some(mkParameterizedType(x.getRawType, typeArgs))
case _ => None
}
@@ -165,7 +172,7 @@ private[json] object Meta {
case x => fail("Raw type of " + x + " not known")
}
- private[json] def mkParameterizedType(owner: Class[_], typeArgs: Seq[Class[_]]) =
+ private[json] def mkParameterizedType(owner: Type, typeArgs: Seq[Type]) =
new ParameterizedType {
def getActualTypeArguments = typeArgs.toArray
def getOwnerType = owner

0 comments on commit 0e4cb6d

Please sign in to comment.