forked from FasterXML/jackson-module-scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write regression test for FasterXML#109. No further changes needed be…
…yond the databind changes.
- Loading branch information
1 parent
1029739
commit 35fed9f
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/test/scala/com/fasterxml/jackson/module/scala/ser/TransientFieldTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}""" | ||
} | ||
} |