Skip to content
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

Integer runtime value in a collection typed as Double #275

Open
l15k4 opened this issue Jul 20, 2016 · 4 comments
Open

Integer runtime value in a collection typed as Double #275

l15k4 opened this issue Jul 20, 2016 · 4 comments

Comments

@l15k4
Copy link

l15k4 commented Jul 20, 2016

Easily reproducible :

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.core.util.{DefaultPrettyPrinter, MinimalPrettyPrinter}
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper

object ObjMapper extends ObjectMapper with ScalaObjectMapper {
  setSerializationInclusion(JsonInclude.Include.NON_NULL)
  registerModule(DefaultScalaModule)
  val prettyWriter = writer(new DefaultPrettyPrinter)
  val miniWriter = writer(new MinimalPrettyPrinter)
}

case class Foo(timestamp: String, result: Map[String, Double])

class PLAY extends BaseSuite {

  "succeeds" in {
    val json =
      """
        |[ {
        |    "count" : 10800
        |  }
        |]
      """.stripMargin

    val map = ObjMapper.readValue[List[Map[String,Double]]](json).head
    assert(map("count").isInstanceOf[Double])
  }


  "fails" in {
    val json =
      """
        |{
        |  "timestamp" : "2015-01-01T00:00:00.000Z",
        |  "result" : {
        |    "count" : 10800
        |  }
        |}
      """.stripMargin

    val map = ObjMapper.readValue[Foo](json).result
    assert(map("count").isInstanceOf[Double])
  }

}
@the-ricker
Copy link

Is this issue scheduled to be fixed?

@Diagoras
Copy link
Contributor

I've also run into this one - might take a crack at resolving it when I have the time.

@tewe
Copy link

tewe commented Oct 16, 2020

This is covered in the FAQ

@pjfanning
Copy link
Member

https://github.com/pjfanning/jackson-scala-reflect-extensions may be an option for people running in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants