Permalink
Browse files

Merge pull request #11 from choplin/richvalue-as

fix RichValue#as
  • Loading branch information...
2 parents 1ed81be + 25daf74 commit 3ba6561cdcca785a0f20be4d2d229ba93951a419 @takezoux2 takezoux2 committed Mar 3, 2013
@@ -18,6 +18,7 @@
package org.msgpack.conversion
+import org.msgpack.scalautil.MyParameterizedType
import org.msgpack.MessagePack
import org.msgpack.`type`.{ValueFactory, Value}
@@ -60,7 +61,8 @@ class RichValue(messagePack : MessagePack,value : Value){
}
def as[T](implicit manifest : Manifest[T]) : T = {
- messagePack.convert(value,manifest.erasure.asInstanceOf[Class[T]])
+ val t = messagePack.lookup(MyParameterizedType(manifest))
+ messagePack.convert(value, t).asInstanceOf[T]
}
def asMap[K,V](implicit keyManife : Manifest[K] , valueManife : Manifest[V]) : Map[K,V] = {
@@ -101,4 +103,4 @@ class RichValue(messagePack : MessagePack,value : Value){
}
-}
+}
@@ -144,8 +144,18 @@ class ImplicitConversionTest extends SpecificationWithJUnit{
bValue must_== 2
}
+ "convert value to tuple using RichValue#as" in{
+ import ScalaMessagePack._
+
+ val t = (1,"foo")
+ val data = writeV(t)
+ val decoded = readAsValue(data)
+ val richValue : RichValue = decoded
+ val r = richValue.as[(Int,String)]
+ r must_== t
+ }
}
-}
+}

0 comments on commit 3ba6561

Please sign in to comment.