Skip to content

Commit c1ff72d

Browse files
committed
add tests
1 parent 16d62c0 commit c1ff72d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/test/scala/tools/jackson/module/scala/deser/CaseClassDeserializerTest.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import tools.jackson.databind.annotation.JsonDeserialize
55
import tools.jackson.databind.json.JsonMapper
66
import tools.jackson.databind.{DatabindException, ObjectMapper, ObjectReader, PropertyNamingStrategies}
77
import tools.jackson.module.scala.DefaultScalaModule
8+
import tools.jackson.module.scala.ser.{ClassWithOnlyUnitField, ClassWithUnitField}
89

910
import java.time.LocalDateTime
1011

@@ -162,4 +163,17 @@ class CaseClassDeserializerTest extends DeserializerTest {
162163
val result = deserialize("""{"value":"AQID"}""", classOf[ArrayHolder])
163164
result.value should equal (Array[Byte](1,2,3))
164165
}
166+
167+
it should "support ClassWithUnitField" in {
168+
val input = """{"intField":2}"""
169+
val result = deserialize(input, classOf[ClassWithUnitField])
170+
result shouldEqual ClassWithUnitField((), 2)
171+
}
172+
173+
//this does not currently work
174+
it should "support ClassWithOnlyUnitField" ignore {
175+
val input = """{}"""
176+
val result = deserialize(input, classOf[ClassWithOnlyUnitField])
177+
result shouldEqual ClassWithOnlyUnitField(())
178+
}
165179
}

src/test/scala/tools/jackson/module/scala/ser/CaseClassSerializerTest.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ case class PrivateDefaultFields(
6161
@JsonProperty lastName: String = "Freeman"
6262
)
6363

64+
case class ClassWithUnitField(field: Unit, intField: Int)
65+
case class ClassWithOnlyUnitField(field: Unit)
66+
6467
class CaseClassSerializerTest extends SerializerTest {
6568

6669
case class NestedClass(field: String)
@@ -193,4 +196,12 @@ class CaseClassSerializerTest extends SerializerTest {
193196
val foo = new Foo(java.util.Arrays.asList("foo", "bar"))
194197
serialize(foo) should equal ("""{"strings":["foo","bar"]}""")
195198
}
199+
200+
it should "serialize ClassWithUnitField" in {
201+
serialize(ClassWithUnitField((), 2)) shouldEqual """{"intField":2}"""
202+
}
203+
204+
it should "serialize ClassWithOnlyUnitField" in {
205+
serialize(ClassWithOnlyUnitField(())) shouldEqual """{}"""
206+
}
196207
}

0 commit comments

Comments
 (0)