-
-
Notifications
You must be signed in to change notification settings - Fork 142
Parameterized type violated when deserializing an Option #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
Unfortunately this latter is not a solution for "deeper" types, e.g. Option[Seq[Int]]. Jackson believes that it is not a compatible type (that being a collection-like type of a collection-like type of a simple type). I've not yet had time to dig deeper, but I suspect that it is a nontrivial fix. |
I doubt there is a fix for the nested container types. The JVM sees that as Option[Seq[Object]]. Scala just doesn't provide enough type information to figure that out, and the JsonDeserialize option only works for one layer down. |
@kralikba I'm not sure I understand what you mean by "deeper" types. I would expect Option[Seq[T]] to deserialize (and serialize) correctly. |
@nbauernfeind E.g. the following example: val mapper = new ObjectMapper with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)
case class Y(os: Option[Seq[Int]])
println(mapper.readValue[Y]("{}"))
case class X(@JsonDeserialize(contentAs = classOf[java.lang.Integer]) os: Option[Seq[Int]])
println(mapper.readValue[X]("{}")) Outputs
|
Thanks for your example. Class I've verified, as @chasebradford says, that the JVM/Jackson is only able to detect the The code does indeed throw the expected exception if you directly use a I believe that this can be improved by using Scala reflection in scala 2.11+, and I would like to do this during/for Jackson 2.8.x. Until then, however, I do not think I can make this any better. I will keep it at the top of my mind though. Maybe @cowtowncoder has some ideas that we're not yet taking advantage of. Your [suboptimal] work arounds:
|
I can deserialize just about anything into an
Option
:Using:
The text was updated successfully, but these errors were encountered: