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

Weird mapper inconsistency based on how the json is created #49

Open
BenFradet opened this issue Mar 16, 2019 · 0 comments
Open

Weird mapper inconsistency based on how the json is created #49

BenFradet opened this issue Mar 16, 2019 · 0 comments

Comments

@BenFradet
Copy link
Contributor

I have noticed a weird inconsistency depending on how the json is created when interacting with the mapper (c.f. #48):

import cats.syntax.either._
import cats.syntax.eq._
import io.circe.Json
import io.circe.literal._
import io.circe.syntax._

val json1 = json"""{"latitude": 43.1, "longitude": 32.1}""" // same with im.circe.parser.parse
val json2 = Json.obj("latitude" := Json.fromDoubleOrNull(43.1), "longitude" := Json.fromDoubleOrNull(32.1))

println(json1 === json2) // true

// a lib I'm using requires me to convert it to an object
val pojo1 = io.circe.jackson.mapper.convertValue(json1, classOf[Object])
val pojo2 = io.circe.jackson.mapper.convertValue(json2, classOf[Object])

println(pojo1 == pojo2) // false

// String
val c1 = Either.catchNonFatal(
  pojo1.asInstanceOf[java.util.HashMap[Object, Object]].get("latitude").getClass)
// Double
val c2 = Either.catchNonFatal(
  pojo2.asInstanceOf[java.util.HashMap[Object, Object]].get("latitude").getClass)

println(c1)
println(c2)

using circe-literal or parse doubles get turned to strings whereas they stay doubles when creating jsons in line.

Here is a scastie reproducing the issue https://scastie.scala-lang.org/VMydlc7ITW2PYBn2NgizUw . However it relies on #48.

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

1 participant