mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-19 13:02:13 +01:00
Fix big bug.
I had gotten order of MessagePackObject field from order of reflection methods.But it changes depends on order of calling in some environment(Scala's optimization or Java's specification?). So I change to get it from order of reflection fields.
This commit is contained in:
parent
ed3ead06fe
commit
f199b80453
@ -396,7 +396,7 @@ class ScalaFieldEntryReader extends IFieldEntryReader{
|
||||
}*/
|
||||
// In some situation, reflection returns wrong ordered getter methods compare with declaration order.
|
||||
// So to avoid such situation, list up props with setter methods
|
||||
for(s <- setters){
|
||||
/*for(s <- setters){
|
||||
getters.get(s._1).map( g => {
|
||||
if(sameType_?(g,s._2)){
|
||||
val name = s._1
|
||||
@ -409,7 +409,42 @@ class ScalaFieldEntryReader extends IFieldEntryReader{
|
||||
props +=(name -> (g,s._2,f))
|
||||
}
|
||||
})
|
||||
}*/
|
||||
// order of methods changes depends on call order, NOT declaration.
|
||||
|
||||
def getterAndSetter(name : String) : Option[(Method,Method)] = {
|
||||
if(getters.contains(name) && setters.contains(name)){
|
||||
val getter = getters(name)
|
||||
val setter = setters(name)
|
||||
if(getter.getReturnType == setter.getParameterTypes()(0)){
|
||||
Some(getter -> setter)
|
||||
}else{
|
||||
None
|
||||
}
|
||||
}else None
|
||||
}
|
||||
def recursiveFind( clazz : Class[_]) : Unit = {
|
||||
if(clazz.getSuperclass != classOf[Object]){
|
||||
recursiveFind(clazz.getSuperclass)
|
||||
}
|
||||
for(f <- clazz.getDeclaredFields){
|
||||
val name =f.getName
|
||||
getterAndSetter(name) match{
|
||||
case Some((g,s)) => props +=( name -> (g,s,f))
|
||||
case None => {
|
||||
if(name.startsWith("_")){
|
||||
val sname = name.substring(1)
|
||||
getterAndSetter(sname) match{
|
||||
case Some((g,s)) => props +=( sname -> (g,s,f))
|
||||
case None =>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
recursiveFind(targetClass)
|
||||
|
||||
props
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ import scala.collection.mutable.LinkedList
|
||||
*
|
||||
*/
|
||||
@RunWith(classOf[JUnitSuiteRunner])
|
||||
class CollectionPackSpec extends Specification with JUnit {
|
||||
class CollectionPackTest extends Specification with JUnit {
|
||||
|
||||
"ScalaMessagePack" should {
|
||||
"pack scala-list" in {
|
||||
|
@ -32,12 +32,15 @@ class SampleClass2 extends SampleClass with SampleTrait {
|
||||
@Index(3)
|
||||
var sampleClass2Name : String = "sampleclass2"
|
||||
|
||||
// Support getter/setter but must have _{name} field!
|
||||
private var _sampleClass2Num : Int = 0
|
||||
@Index(0)
|
||||
def sampleClass2Num : Int = 22
|
||||
def sampleClass2Num_=(v : Int) = {}
|
||||
def sampleClass2Num : Int = _sampleClass2Num
|
||||
def sampleClass2Num_=(v : Int) = {_sampleClass2Num = v}
|
||||
|
||||
val notProperty : String ="This is not prop.Only getter"
|
||||
|
||||
private var _wrongValue : Int = 0
|
||||
// wrong property
|
||||
def wrongValue : Int = 53
|
||||
def wrongValue_=(v : String) = {}
|
||||
|
@ -16,7 +16,7 @@ import org.specs.runner.{ JUnitSuiteRunner, JUnit }
|
||||
*
|
||||
*/
|
||||
@RunWith(classOf[JUnitSuiteRunner])
|
||||
class ScalaFieldEntryReaderSpec extends Specification with JUnit {
|
||||
class ScalaFieldEntryReaderTest extends Specification with JUnit {
|
||||
|
||||
"ScalaFieldEntryReader" should {
|
||||
|
||||
@ -56,15 +56,16 @@ class ScalaFieldEntryReaderSpec extends Specification with JUnit {
|
||||
|
||||
val props = reader.findPropertyMethods(c)
|
||||
|
||||
println(props.keys)
|
||||
println("props=" + props.keys)
|
||||
|
||||
props.size must be_==(6)
|
||||
props must haveKey("name")
|
||||
props must haveKey("number")
|
||||
props must haveKey("traitName")
|
||||
props must haveKey("traitNum")
|
||||
props must haveKey("sampleClass2Name")
|
||||
props must haveKey("sampleClass2Num")
|
||||
val l = props.toList
|
||||
l(0)._1 must_== "name"
|
||||
l(1)._1 must_== "number"
|
||||
l(2)._1 must_== "sampleClass2Name"
|
||||
l(3)._1 must_== "sampleClass2Num"
|
||||
l(4)._1 must_== "traitName"
|
||||
l(5)._1 must_== "traitNum"
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user