File tree 2 files changed +21
-4
lines changed
main/scala/com/fasterxml/jackson/module/scala/experimental
test/scala/com/fasterxml/jackson/module/scala/experimental
2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,12 @@ trait ScalaObjectMapper {
72
72
throw new IllegalArgumentException (" Need exactly 1 type parameter for collection like types (" + clazz.getName+ " )" )
73
73
}
74
74
getTypeFactory.constructCollectionLikeType(clazz, typeArguments(0 ))
75
+ } else if (isReference(clazz)) {
76
+ val typeArguments = m.typeArguments.map(constructType(_)).toArray
77
+ if (typeArguments.length != 1 ) {
78
+ throw new IllegalArgumentException (" Need exactly 1 type parameter for reference types (" + clazz.getName+ " )" )
79
+ }
80
+ getTypeFactory.constructReferenceType(clazz, typeArguments(0 ))
75
81
} else {
76
82
val typeArguments = m.typeArguments.map(constructType(_)).toArray
77
83
getTypeFactory.constructParametrizedType(clazz, clazz, typeArguments : _* )
@@ -333,10 +339,14 @@ trait ScalaObjectMapper {
333
339
MAP .isAssignableFrom(c)
334
340
}
335
341
336
- private val ITERABLE = classOf [collection.Iterable [_]]
337
342
private val OPTION = classOf [Option [_]]
343
+ private def isReference (c : Class [_]): Boolean = {
344
+ OPTION .isAssignableFrom(c)
345
+ }
346
+
347
+ private val ITERABLE = classOf [collection.Iterable [_]]
338
348
private def isCollectionLike (c : Class [_]): Boolean = {
339
- ITERABLE .isAssignableFrom(c) || OPTION .isAssignableFrom(c)
349
+ ITERABLE .isAssignableFrom(c)
340
350
}
341
351
342
352
}
Original file line number Diff line number Diff line change @@ -196,8 +196,15 @@ class ScalaObjectMapperTest extends FlatSpec with Matchers {
196
196
assert(result.isInstanceOf [collection.Map [_, _]])
197
197
}
198
198
199
- it should " read a option values from a JSON array" in {
200
- val result = mapper.readValue[List [Option [String ]]](toplevelOptionArrayJson)
199
+ it should " read option values into List from a JSON array" in {
200
+ val result = mapper.readValue[java.util.ArrayList [Option [String ]]](toplevelOptionArrayJson)
201
+ import scala .collection .JavaConversions ._
202
+ result(0 ) should equal(Some (" some" ))
203
+ result(1 ) should equal(None )
204
+ }
205
+
206
+ it should " read option values into Array from a JSON array" in {
207
+ val result = mapper.readValue[Array [Option [String ]]](toplevelOptionArrayJson)
201
208
result(0 ) should equal(Some (" some" ))
202
209
result(1 ) should equal(None )
203
210
}
You can’t perform that action at this time.
0 commit comments