-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39996b3
commit fe15b83
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/test/scala/com/fasterxml/jackson/module/scala/deser/TestInnerClass.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,50 @@ | ||
package com.fasterxml.jackson.module.scala.deser | ||
|
||
import org.scalatest.matchers.ShouldMatchers | ||
import org.scalatest.FlatSpec | ||
import org.junit.runner.RunWith | ||
import org.scalatest.junit.JUnitRunner | ||
import com.fasterxml.jackson.module.scala.DefaultScalaModule | ||
|
||
object Dog | ||
{ | ||
def apply(n: String, thinking: Boolean) = { | ||
val dog = new Dog | ||
dog.name = n | ||
dog.brain = new dog.Brain | ||
dog.brain.isThinking = thinking | ||
dog | ||
} | ||
} | ||
class Dog | ||
{ | ||
var name: String = _ | ||
var brain: Brain = _ | ||
|
||
class Brain { | ||
var isThinking: Boolean = _ | ||
def parentName = name | ||
} | ||
|
||
} | ||
|
||
// Cribbed from the same named test in jackson-databind | ||
@RunWith(classOf[JUnitRunner]) | ||
class TestInnerClass extends DeserializerTest with FlatSpec with ShouldMatchers { | ||
|
||
def module = DefaultScalaModule | ||
|
||
"Deserializer" should "support nested inner classes as values" in { | ||
val input = Dog("Smurf", thinking = true) | ||
val json = mapper.writeValueAsString(input) | ||
val output = deserialize[Dog](json) | ||
|
||
output.name should be === ("Smurf") | ||
output.brain should not be (null) | ||
output.brain.isThinking should be (true) | ||
output.brain.parentName should be === ("Smurf") | ||
output.name = "Foo" | ||
output.brain.parentName should be === ("Foo") | ||
} | ||
|
||
} |