From 35fed9f8811db8833ec994e5cb29f1d252733a90 Mon Sep 17 00:00:00 2001 From: Nathaniel Bauernfeind Date: Tue, 26 Apr 2016 09:43:07 -0400 Subject: [PATCH] Write regression test for #109. No further changes needed beyond the databind changes. --- .../module/scala/ser/TransientFieldTest.scala | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/scala/com/fasterxml/jackson/module/scala/ser/TransientFieldTest.scala diff --git a/src/test/scala/com/fasterxml/jackson/module/scala/ser/TransientFieldTest.scala b/src/test/scala/com/fasterxml/jackson/module/scala/ser/TransientFieldTest.scala new file mode 100644 index 000000000..afd18e4f7 --- /dev/null +++ b/src/test/scala/com/fasterxml/jackson/module/scala/ser/TransientFieldTest.scala @@ -0,0 +1,42 @@ +package com.fasterxml.jackson.module.scala.ser + +import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyOrder} +import com.fasterxml.jackson.databind.MapperFeature +import com.fasterxml.jackson.module.scala.DefaultScalaModule +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +object TransientFieldTest { + @JsonPropertyOrder(Array("x")) + class ClassyTransient { + val x = 42 + @transient + val value = 3 + def getValue = value + } + + class IgnoredTransient { + @transient + val value = 3 + val x = 42 + } +} + +@RunWith(classOf[JUnitRunner]) +class TransientFieldTest extends SerializerTest { + import TransientFieldTest._ + + val module = DefaultScalaModule + + "DefaultScalaModule" should "normally ignore @transient annotations" in { + serialize(new ClassyTransient) shouldBe """{"x":42,"value":3}""" + } + + it should "respect @transient annotation when feature enabled" in { + serialize(new ClassyTransient, newMapper.enable(MapperFeature.PROPAGATE_TRANSIENT_MARKER)) shouldBe """{"x":42}""" + } + + it should "normally ignore @transient fields without getters" in { + serialize(new IgnoredTransient) shouldBe """{"x":42}""" + } +}