Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface ExampleKotlinInterface {
- val name: String
- }
- interface ExampleKotlinInterfaceSubclass : ExampleKotlinInterface {
- override var name: String
- }
- abstract class ExampleKotlinImpl(@SerializedName("name") override val name: String = "zach") : ExampleKotlinInterface
- class ExampleKotlinImplSubclass(override var name: String) : ExampleKotlinImpl(name), ExampleKotlinInterfaceSubclass
- java.lang.IllegalArgumentException: class com.example.kotlingetterinterfaceexample.ExampleKotlinImplSubclass declares multiple JSON fields named name
- at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:172)
- at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
- at com.google.gson.Gson.getAdapter(Gson.java:458)
- at com.google.gson.Gson.fromJson(Gson.java:926)
- at com.google.gson.Gson.fromJson(Gson.java:892)
- at com.google.gson.Gson.fromJson(Gson.java:841)
- at com.google.gson.Gson.fromJson(Gson.java:813)
- at com.example.kotlingetterinterfaceexample.ExampleGsonParseTests.testParseObject(ExampleGsonParseTests.kt:13)
- val json = "{ "name" : "test" }"
- val result = Gson().fromJson(json, ExampleKotlinImplSubclass::class.java)
- assertNotNull(result)
- assertEquals("test", result.name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement