Skip to content

Commit ac0d8a4

Browse files
committed
Create NumberSerializerTest.scala
1 parent c9df49b commit ac0d8a4

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package tools.jackson.module.scala.ser
2+
3+
import com.fasterxml.jackson.annotation.JsonFormat
4+
import tools.jackson.databind.cfg.MutableConfigOverride
5+
import tools.jackson.module.scala.{DefaultScalaModule, JacksonModule}
6+
7+
class NumberSerializerTest extends SerializerTest {
8+
9+
val module: JacksonModule = DefaultScalaModule
10+
11+
"NumberSerializer" should "serialize BigDecimal as a number" in {
12+
serialize(BigDecimal("123.456")) shouldBe "123.456"
13+
}
14+
15+
it should "serialize BigDecimal as a number (JsonFormat.Shape.STRING)" in {
16+
val builder = newBuilder
17+
.withConfigOverride(classOf[BigDecimal],
18+
(c: MutableConfigOverride) => c.setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING)))
19+
serialize(BigDecimal("123.456"), builder.build()) shouldBe """"123.456""""
20+
}
21+
22+
it should "serialize BigInt as a number" in {
23+
serialize(BigInt("12345678901234567890")) shouldBe "12345678901234567890"
24+
}
25+
26+
it should "serialize Int as a number" in {
27+
serialize(42) shouldBe "42"
28+
}
29+
30+
it should "serialize Long as a number" in {
31+
serialize(12345678901234L) shouldBe "12345678901234"
32+
}
33+
34+
}

0 commit comments

Comments
 (0)