Skip to content

Commit

Permalink
add yaml test
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Oct 30, 2023
1 parent e3deeb4 commit 66d8dc6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ libraryDependencies ++= Seq(
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % jacksonVersion % Test,
"com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % jacksonVersion % Test,
"com.fasterxml.jackson.datatype" % "jackson-datatype-jdk8" % jacksonVersion % Test,
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % jacksonVersion % Test,
"com.fasterxml.jackson.jaxrs" % "jackson-jaxrs-json-provider" % jacksonVersion % Test,
"com.fasterxml.jackson.module" % "jackson-module-jsonSchema" % jacksonVersion % Test,
"javax.ws.rs" % "javax.ws.rs-api" % "2.1.1" % Test,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.fasterxml.jackson.module.scala.yaml

import com.fasterxml.jackson.databind.{Module, ObjectMapper}
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.scala.yaml.YamlSpec.Person
import com.fasterxml.jackson.module.scala.{DefaultScalaModule, JacksonTest}

object YamlSpec {
case class Person(name: String, id: Int, titles: List[String], permanent: Boolean)
}

class YamlSpec extends JacksonTest {
override def module: Module = DefaultScalaModule

behavior of "ObjectMapper with YAML and DefaultScalaModule"

it should "serialize/deserialize Person" in {
val p = Person("cb", 12, List("h1", "h2"), true)
val mapper = new ObjectMapper(new YAMLFactory())
mapper.registerModule(DefaultScalaModule)

val str = mapper.writeValueAsString(p)
val p1 = mapper.readValue(str, classOf[Person])
p1 shouldEqual p
}
}

0 comments on commit 66d8dc6

Please sign in to comment.