-
Notifications
You must be signed in to change notification settings - Fork 72
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
Timestamp inconsistent JSON representation when using Document #1622
Comments
is this specific to timestamps or just #1579? |
These two are connected, I think the issue you posted is more like a long term fix and having more ADT members instead of just The example which I pasted above does not apply to Jsoniter has the issue, where two |
To expand on the Jsoniter issue: //> using scala "3.3"
//> using dep "com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-core::2.31.3"
//> using compileOnly.dep "com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-macros::2.31.3"
import com.github.plokhotnyuk.jsoniter_scala.macros._
import com.github.plokhotnyuk.jsoniter_scala.core._
case class User(bigDecimal: BigDecimal)
given userCodec: JsonValueCodec[User] = JsonCodecMaker.make
val one = BigDecimal(1) + (BigDecimal(0.0))
val two = BigDecimal(1)
println(one == two)
println(one)
println(two) prints
|
I don't understand yet how it connects to jsoniter-scala. Here is the same output for last 5 lines, but without using jsoniter-scala: $ scala-cli
Welcome to Scala 3.5.2 (21.0.5, Java Java HotSpot(TM) 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> val one = BigDecimal(1) + (BigDecimal(0.0))
| val two = BigDecimal(1)
| println(one == two)
| println(one)
| println(two)
true
1.0
1
val one: BigDecimal = 1.0
val two: BigDecimal = 1 |
Depending on if we encode timestamp value to JSON directly or via
The problem can as well be fixed in smithy4s, if I were to make a decision. But coming back to to jsoniter, it could also be fixed there and encode big decimals consistently (question is, would that be It could as well be that the above is perfectly valid with the JSON specs and common "problem" among JSON libs. |
The jsoniter-scala serialize Currently you have an issue of using different scales: scala> val one = (BigDecimal(1) + (BigDecimal(0.0)))
| val two = BigDecimal(1)
| println(s"one.scale=${one.scale}, two.scale=${two.scale}")
one.scale=1, two.scale=0
val one: BigDecimal = 1.0
val two: BigDecimal = 1 To mitigate difference in text representation just round them to the same scale. |
Makes sense, thank you. |
Timestamp with epoch-seconds is inconsistently represented currently when encoding directly to JSON vs using a Document as an intermediate layer.
Reproduction
prints
The fix should be rather simple, I can create a PR once this issue is acked
The text was updated successfully, but these errors were encountered: