spray-json
spray-json copied to clipboard
Option[Int] cannot convert to java.lang.Integer
I have a case class with a id attribute that's an Option[Int]. When I try to serialize it as a JSON I got the following error:
case class Development(id: Option[Int], ...)
development.toJson
java.lang.ClassCastException: scala.Some cannot be cast to java.lang.Integer
at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:105)
at spray.json.BasicFormats$IntJsonFormat$.write(BasicFormats.scala:25)
at spray.json.ProductFormats$class.productElement2Field(ProductFormats.scala:45)
Adding NullOptions make it work but it doesn't make sense at all. If the value is None I want it to do not render the field. Besides that, in this specific case the id field has a value(Some(1)) and even with that I got the ClassCastException.
This sounds like a bug in spray-json. What do you guys think?
This looks strange. Could you provide us with a small complete example demonstrating the problem?
Facing the same issue.
@nykolaslima did you manage to solve this?
I solved this by deleting my local ivy2 cache and running sbt clean compile