Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

fix RichValue#as #11

Merged
merged 1 commit into from about 1 year ago

2 participants

choplin Yoshiteru Takeshita
choplin

to enable parametrized type to be converted from value using RichValue#as

e.g. readAsValue(writeV((1,2))).as[(Int,Int)] doesn't work now.

NOTE: This commit requires the commit of msgpack-java (choplin/msgpack-java@50d7709).
A pull request for this commit has already been opend, but not merged yet.

choplin fix RichValue#as
to enable parametrized type to be converted from value using RichValue#as
25daf74
OZAWA Tsuyoshi oza referenced this pull request in msgpack/msgpack-java February 26, 2013
Merged

overload convert method with Template parameter #33

Yoshiteru Takeshita takezoux2 merged commit 3ba6561 into from March 02, 2013
Yoshiteru Takeshita takezoux2 closed this March 02, 2013
Yoshiteru Takeshita
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 27, 2013
choplin fix RichValue#as
to enable parametrized type to be converted from value using RichValue#as
25daf74
This page is out of date. Refresh to see the latest.
6  src/main/scala/org/msgpack/conversion/RichValue.scala
@@ -18,6 +18,7 @@
18 18
 
19 19
 package org.msgpack.conversion
20 20
 
  21
+import org.msgpack.scalautil.MyParameterizedType
21 22
 import org.msgpack.MessagePack
22 23
 import org.msgpack.`type`.{ValueFactory, Value}
23 24
 
@@ -60,7 +61,8 @@ class RichValue(messagePack : MessagePack,value : Value){
60 61
   }
61 62
 
62 63
   def as[T](implicit manifest : Manifest[T]) : T = {
63  
-    messagePack.convert(value,manifest.erasure.asInstanceOf[Class[T]])
  64
+    val t = messagePack.lookup(MyParameterizedType(manifest))
  65
+    messagePack.convert(value, t).asInstanceOf[T]
64 66
   }
65 67
 
66 68
   def asMap[K,V](implicit keyManife : Manifest[K] , valueManife : Manifest[V]) : Map[K,V] = {
@@ -101,4 +103,4 @@ class RichValue(messagePack : MessagePack,value : Value){
101 103
   }
102 104
 
103 105
 
104  
-}
  106
+}
12  src/test/scala/org/msgpack/ImplicitConversionTest.scala
@@ -133,8 +133,18 @@ class ImplicitConversionTest extends SpecificationWithJUnit{
133 133
     }
134 134
 
135 135
 
  136
+    "convert value to tuple using RichValue#as" in{
  137
+      import ScalaMessagePack._
  138
+
  139
+      val t = (1,"foo")
  140
+      val data = writeV(t)
  141
+      val decoded = readAsValue(data)
  142
+      val richValue : RichValue = decoded
  143
+      val r = richValue.as[(Int,String)]
  144
+      r must_== t
  145
+    }
136 146
   }
137 147
 
138 148
 
139 149
 
140  
-}
  150
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.