Skip to content

Instantly share code, notes, and snippets.

Created June 4, 2016 11:50
Show Gist options
  • Save anonymous/a6e12ccd37e499eb5dbe9938da3760a2 to your computer and use it in GitHub Desktop.
Save anonymous/a6e12ccd37e499eb5dbe9938da3760a2 to your computer and use it in GitHub Desktop.
Classed defined in function vs. Top Level one
@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