Skip to content

Commit 6d44fdb

Browse files
committed
add deserializer test
1 parent 447a2fe commit 6d44fdb

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
6767

6868
- name: Check that workflows are up to date
69-
run: sbt -J-Xmx2G '++${{ matrix.scala }}' 'project /' githubWorkflowCheck
69+
run: sbt -J-Xmx2G githubWorkflowCheck
7070

7171
- run: sbt -J-Xmx2G '++${{ matrix.scala }}' test mimaReportBinaryIssues
7272

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
88

99
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.0")
1010

11-
addSbtPlugin("org.typelevel" % "sbt-typelevel-sonatype-ci-release" % "0.5.0-M5")
11+
addSbtPlugin("org.typelevel" % "sbt-typelevel-sonatype-ci-release" % "0.5.0-M6")
1212

1313
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10")
1414

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.fasterxml.jackson.module.scala.deser
2+
3+
import com.fasterxml.jackson.databind.DeserializationFeature
4+
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException
5+
import com.fasterxml.jackson.module.scala.deser.IgnorableFieldDeserializerTest.ExtractFields
6+
import com.fasterxml.jackson.module.scala.{DefaultScalaModule, JacksonModule}
7+
8+
object IgnorableFieldDeserializerTest {
9+
case class ExtractFields(s: String, i: Int)
10+
}
11+
12+
class IgnorableFieldDeserializerTest extends DeserializerTest {
13+
14+
lazy val module: JacksonModule = DefaultScalaModule
15+
16+
"An ObjectMapper with the DefaultScalaModule" should "fail if field is not expected" in {
17+
val mapper = newMapper
18+
intercept[UnrecognizedPropertyException] {
19+
mapper.readValue(genJson(100), classOf[ExtractFields])
20+
}
21+
}
22+
23+
it should "succeed if field is not expected" in {
24+
val mapper = newBuilder
25+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
26+
.build()
27+
val ef = mapper.readValue(genJson(1000), classOf[ExtractFields])
28+
ef.s shouldEqual "s"
29+
ef.i shouldEqual 1
30+
}
31+
32+
private def genJson(size: Int): String = {
33+
s"""{"s":"s","n":${"7" * size},"i":1}"""
34+
}
35+
36+
}

0 commit comments

Comments
 (0)