This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Scala primitives inside a List become "Object" #8
Comments
A test to reproduce this problem, based on an existing test in
|
I think it's technically impossible to determine the type of a scala primitive from Java (or scala for that matter). There's really no other way to do it than use java.lang.Integer for types. Even |
I've tested this against the current develop branch (08cd397) and the List passes as and diff --git a/src/test/scala/ScalaModelTest.scala b/src/test/scala/ScalaModelTest.scala
index 6321f6b..c75756c 100644
--- a/src/test/scala/ScalaModelTest.scala
+++ b/src/test/scala/ScalaModelTest.scala
@@ -56,8 +56,20 @@ class ScalaModelTest extends FlatSpec with Matchers {
prop.isInstanceOf[ArrayProperty] should be (true)
prop.asInstanceOf[ArrayProperty].getItems.getType should be ("number")
}
+
+ it should "read a model with list of ints" in {
+ val schemas = ModelConverters.getInstance().readAll(classOf[ModelWithIntList]).asScala
+ val model = schemas("ModelWithIntList")
+ val prop = model.getProperties().get("ints")
+ prop.isInstanceOf[ArrayProperty] should be (true)
+ prop.asInstanceOf[ArrayProperty].getItems.getType should be ("number")
+ }
}
+case class ModelWithIntList (
+ ints: List[Int]
+)
+
case class ModelWithVector (
name: String,
friends: Vector[String]) |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
A property of type
List[String]
will be correctly described as an array of strings, but if it'sList[Int]
it'll be described as an array of objects. The same goes for any parameterized type, if the type parameter is a primitive— for instance, when I tried to add support forOption[T]
(see issue 7), I found thatOption[String]
worked correctly butOption[Int]
did not.This may be a problem with the underlying Jackson Scala module; a comment on this issue mentioned that Java reflection sometimes misreads Scala primitives as being java.lang.Object. It looked like someone had fixed that in jackson-scala-module, but maybe not. Whatever the reason, it's not currently possible to document a schema that has an array of numbers or booleans in it.
The text was updated successfully, but these errors were encountered: