Created
June 4, 2016 11:50
-
-
Save anonymous/a6e12ccd37e499eb5dbe9938da3760a2 to your computer and use it in GitHub Desktop.
Classed defined in function vs. Top Level one
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
@Test fun json_test_with_nested_data_class() { | |
data class MyNestedClass(val name: String, val password: String) | |
val x: MyNestedClass = MyNestedClass("hoang", "1234") | |
val result = GsonBuilder().create().toJson(x) // -> null | |
result.should.equal("""{"name":"hoang","password":"1234"}""") | |
} | |
data class MyTopLevelClass(val name: String, val password: String) | |
@Test fun json_test_with_none_nested_data_class() { | |
val x: MyTopLevelClass = MyTopLevelClass("hoang", "1234") | |
val result = GsonBuilder().create().toJson(x) // -> ok | |
result.should.equal("""{"name":"hoang","password":"1234"}""") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment