Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. interface ExampleKotlinInterface {
  2. val name: String
  3. }
  4.  
  5. interface ExampleKotlinInterfaceSubclass : ExampleKotlinInterface {
  6. override var name: String
  7. }
  8.  
  9. abstract class ExampleKotlinImpl(@SerializedName("name") override val name: String = "zach") : ExampleKotlinInterface
  10.  
  11. class ExampleKotlinImplSubclass(override var name: String) : ExampleKotlinImpl(name), ExampleKotlinInterfaceSubclass
  12.  
  13. java.lang.IllegalArgumentException: class com.example.kotlingetterinterfaceexample.ExampleKotlinImplSubclass declares multiple JSON fields named name
  14.  
  15. at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:172)
  16. at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
  17. at com.google.gson.Gson.getAdapter(Gson.java:458)
  18. at com.google.gson.Gson.fromJson(Gson.java:926)
  19. at com.google.gson.Gson.fromJson(Gson.java:892)
  20. at com.google.gson.Gson.fromJson(Gson.java:841)
  21. at com.google.gson.Gson.fromJson(Gson.java:813)
  22. at com.example.kotlingetterinterfaceexample.ExampleGsonParseTests.testParseObject(ExampleGsonParseTests.kt:13)
  23.  
  24. val json = "{ "name" : "test" }"
  25.  
  26. val result = Gson().fromJson(json, ExampleKotlinImplSubclass::class.java)
  27.  
  28. assertNotNull(result)
  29.  
  30. assertEquals("test", result.name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement