@@ -3,20 +3,21 @@ package com.github.plokhotnyuk.jsoniter_scala.macros
3
3
import com .epam .deltix .dfp .{Decimal64 , Decimal64Utils }
4
4
import com .github .plokhotnyuk .jsoniter_scala .core ._
5
5
import com .github .plokhotnyuk .jsoniter_scala .macros .JsonCodecMaker ._
6
+ import java .math .MathContext
6
7
7
8
class JsonCodecMakerDecimal64Spec extends VerifyingSpec {
8
9
import Decimal64Codec ._
9
10
10
11
" Decimal64Codec" should {
11
12
" deserialize both numeric and string representation of numbers to canonized Decimal64 values" in {
12
13
verifyDeser(make[List [Decimal64 ]],
13
- List (Decimal64 .ONE_TENTH , Decimal64 .MILLION , Decimal64 .fromLong(4503599627370497L ), Decimal64 .parse(" 1.23456789e+309" ), Decimal64 .MAX_VALUE ),
14
- """ [0.1,"001000000",4503599627370497,1.23456789e+309,"9999999999999999e+369"]""" )
14
+ List (Decimal64 .ONE_TENTH , Decimal64 .MILLION , Decimal64 .fromLong(4503599627370497L ), Decimal64 .parse(" 1.23456789e+309" ), Decimal64 .MAX_VALUE , Decimal64 .parse( " 0.12345678901234565 " ) ),
15
+ """ [0.1,"001000000",4503599627370497,1.23456789e+309,"9999999999999999e+369",0.12345678901234565 ]""" )
15
16
}
16
17
" serialize Decimal64 values into numeric or string representation depending on number of mantissa bits of canonized in-memory representation" in {
17
18
verifySer(make[List [Decimal64 ]],
18
- List (Decimal64 .ONE_TENTH , Decimal64 .MILLION , Decimal64 .fromLong(4503599627370497L ), Decimal64 .parse(" 1.23456789e+309" ), Decimal64 .MAX_VALUE ),
19
- """ [0.1,1E+6,"4503599627370497","1.23456789E+309","9.999999999999999E+384"]""" )
19
+ List (Decimal64 .ONE_TENTH , Decimal64 .MILLION , Decimal64 .fromLong(4503599627370497L ), Decimal64 .parse(" 1.23456789e+309" ), Decimal64 .MAX_VALUE , Decimal64 .parse( " 0.12345678901234565 " ) ),
20
+ """ [0.1,1E+6,"4503599627370497","1.23456789E+309","9.999999999999999E+384",0.1234567890123456 ]""" )
20
21
}
21
22
}
22
23
}
@@ -30,7 +31,7 @@ object Decimal64Codec {
30
31
} else {
31
32
in.rollbackToken()
32
33
in.readBigDecimal(null )
33
- }).bigDecimal)))
34
+ }).bigDecimal.plus( MathContext . DECIMAL64 ) )))
34
35
35
36
override def encodeValue (x : Decimal64 , out : JsonWriter ): Unit = {
36
37
val cx = Decimal64Utils .canonize(Decimal64 .toUnderlying(x))
0 commit comments