Skip to content

Commit

Permalink
Test case for gh-32
Browse files Browse the repository at this point in the history
  • Loading branch information
christophercurrie committed Jul 2, 2012
1 parent 03be343 commit 5ce067b
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import org.scalatest.matchers.ShouldMatchers



import com.fasterxml.jackson.module.scala.JacksonModule
import com.fasterxml.jackson.annotation.{JsonIgnoreProperties, JsonProperty}
import com.fasterxml.jackson.module.scala.{DefaultScalaModule, JacksonModule}
import com.fasterxml.jackson.annotation.{JsonInclude, JsonIgnoreProperties, JsonProperty}
import com.fasterxml.jackson.databind.ObjectMapper

case class ConstructorTestCaseClass(intValue: Int, stringValue: String)

Expand Down Expand Up @@ -38,6 +39,12 @@ case class CaseClassWithCompanion(intValue: Int)
@JsonIgnoreProperties(Array("ignore"))
case class JacksonIgnorePropertyTestCaseClass(ignore:String, test:String)


case class NonNullCaseClass1(@JsonInclude(JsonInclude.Include.NON_NULL) foo: Option[String])

case class NonNullCaseClass2(foo: Option[String])


@RunWith(classOf[JUnitRunner])
class CaseClassSerializerTest extends SerializerTest with FlatSpec with ShouldMatchers {

Expand Down Expand Up @@ -94,4 +101,18 @@ class CaseClassSerializerTest extends SerializerTest with FlatSpec with ShouldMa
equal("""{"intValue":42}""")
)
}

def withOptionModule = new JacksonModule with CaseClassSerializerModule with OptionSerializerModule {}
def nonNullMapper: ObjectMapper =
new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)

it should "not write a null value" in {
val o = NonNullCaseClass1(None)
nonNullMapper.writeValueAsString(o) should be ("{}")
}

it should "not also write a null value" in {
val o = NonNullCaseClass2(None)
nonNullMapper.writeValueAsString(o) should be ("{}")
}
}

0 comments on commit 5ce067b

Please sign in to comment.