1
1
package com .fasterxml .jackson .module .scala .introspect
2
2
3
+ import com .fasterxml .jackson .module .scala .introspect .BeanIntrospectorTest .DecodedNameMatcher
3
4
import org .junit .runner .RunWith
4
5
import org .scalatest .junit .JUnitRunner
5
6
import org .scalatest .{Inside , OptionValues , LoneElement , FlatSpec }
@@ -8,63 +9,76 @@ import reflect.NameTransformer
8
9
import com .fasterxml .jackson .module .scala .BaseSpec
9
10
import java .lang .reflect .Member
10
11
11
- class PlainCtorBean (`field-name` : Int )
12
- {
13
- // This needs to exist otherwise it gets optimized away
14
- def x = `field-name`
15
- }
12
+ object BeanIntrospectorTest {
16
13
17
- class ValCtorBean (val `field-name` : Int )
18
- case class ValCaseBean (`field-name` : Int )
14
+ class PlainCtorBean (`field-name` : Int ) {
15
+ // This needs to exist otherwise it gets optimized away
16
+ def x = `field-name`
17
+ }
19
18
20
- class VarCtorBean (var `field-name` : Int )
21
- case class VarCaseBean (var `field-name` : Int )
19
+ class ValCtorBean (val `field-name` : Int )
22
20
23
- class MethodBean
24
- {
25
- def `field-name` = 0
26
- def `field-name_=` (v : Int ) { }
27
- }
21
+ case class ValCaseBean (`field-name` : Int )
28
22
29
- // adding @SerialVersionUID puts a public static final int field on the generated class
30
- // this field should be ignored
31
- @ SerialVersionUID (8675309 )
32
- case class SerialIDBean (field : String ) {
33
- @ transient val shouldBeExluded = 10
34
- @ volatile var alsoExcluded = 20
35
- }
23
+ class VarCtorBean (var `field-name` : Int )
36
24
37
- class StaticMethodBean extends JavaStaticMethods {
38
- val included = " included"
39
- }
25
+ case class VarCaseBean (var `field-name` : Int )
40
26
41
- class Parent {
42
- var parentValue = " parentValue"
43
- }
27
+ class MethodBean {
28
+ def `field-name` = 0
44
29
45
- class Child extends Parent {
46
- var childValue = " childValue"
47
- }
30
+ def `field-name_=` (v : Int ) {}
31
+ }
32
+
33
+ // adding @SerialVersionUID puts a public static final int field on the generated class
34
+ // this field should be ignored
35
+ @ SerialVersionUID (8675309 )
36
+ case class SerialIDBean (field : String ) {
37
+ @ transient val shouldBeExluded = 10
38
+ @ volatile var alsoExcluded = 20
39
+ }
40
+
41
+ class StaticMethodBean extends JavaStaticMethods {
42
+ val included = " included"
43
+ }
44
+
45
+ class Parent {
46
+ var parentValue = " parentValue"
47
+ }
48
48
49
- case class PrivateDefaultBean (private val privateField : String = " defaultValue" )
50
-
51
- trait DecodedNameMatcher {
52
- def decodedName (expectedValue : String ) =
53
- new HavePropertyMatcher [Member , String ] {
54
- def apply (member : Member ) = {
55
- val decodedName = NameTransformer .decode(member.getName)
56
- HavePropertyMatchResult (
57
- decodedName == expectedValue,
58
- " name" ,
59
- expectedValue,
60
- decodedName
61
- )
49
+ class Child extends Parent {
50
+ var childValue = " childValue"
51
+ }
52
+
53
+ case class PrivateDefaultBean (private val privateField : String = " defaultValue" )
54
+
55
+ trait DecodedNameMatcher {
56
+ def decodedName (expectedValue : String ) =
57
+ new HavePropertyMatcher [Member , String ] {
58
+ def apply (member : Member ) = {
59
+ val decodedName = NameTransformer .decode(member.getName)
60
+ HavePropertyMatchResult (
61
+ decodedName == expectedValue,
62
+ " name" ,
63
+ expectedValue,
64
+ decodedName
65
+ )
66
+ }
62
67
}
63
- }
68
+ }
69
+
70
+ class OverloadedGetter {
71
+ var firstName : String = " "
72
+ var lastName : String = " "
73
+
74
+ def firstName (firstName : String ) {}
75
+ def lastName (lastName : String ) {}
76
+ }
64
77
}
65
78
66
79
@ RunWith (classOf [JUnitRunner ])
67
80
class BeanIntrospectorTest extends BaseSpec with Inside with LoneElement with OptionValues with DecodedNameMatcher {
81
+ import BeanIntrospectorTest ._
68
82
69
83
behavior of " BeanIntrospector"
70
84
@@ -280,6 +294,16 @@ class BeanIntrospectorTest extends BaseSpec with Inside with LoneElement with Op
280
294
props should have size 1
281
295
props.head.name shouldBe " privateField"
282
296
}
297
+
298
+ it should " find getters among overloads" in {
299
+ type Bean = OverloadedGetter
300
+
301
+ val beanDesc = BeanIntrospector [Bean ](classOf [Bean ])
302
+ val props = beanDesc.properties
303
+
304
+ props should have size 2
305
+ props.forall ( _.getter.isDefined ) shouldBe true
306
+ }
283
307
}
284
308
285
309
0 commit comments