Skip to content

Commit 2dfafc9

Browse files
committed
Deserialization error of map type fixed
1 parent ca715b0 commit 2dfafc9

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/iris/json/serialization/DeserializerFactory.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,15 @@ object DeserializerFactory {
7070
}
7171

7272
private fun getMapType(type: KType): KType {
73-
val type = type.jvmErasure.allSupertypes.find {
74-
it.jvmErasure == Map::class
75-
} ?: throw IllegalArgumentException("$type is not subclass of Map")
73+
74+
val type = with(type.jvmErasure) {
75+
if (this == Map::class)
76+
type
77+
else
78+
allSupertypes.find {
79+
it.jvmErasure == Map::class
80+
} ?: throw IllegalArgumentException("$type is not subclass of Map")
81+
}
7682
val (key, value) = type.arguments
7783
if (!key.type!!.isSubtypeOf(CharSequence::class.starProjectedType))
7884
throw IllegalStateException("Map key cannot be non CharSequence inherited")

test/iris/json/PureJavaUser.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public final class PureJavaUser {
1717

1818
public int id;
19-
public List<String> type;
19+
public String type;
2020

2121
@PolymorphData(
2222
sourceField = "type",
@@ -43,8 +43,7 @@ public final class PureJavaUser {
4343

4444
public PureJavaUser(int id, String type, Human person1, Human person2) {
4545
this.id = id;
46-
this.type = new ArrayList(1);
47-
this.type.add(type);
46+
this.type = type;
4847
this.person1 = person1;
4948
this.person2 = person2;
5049
}

0 commit comments

Comments
 (0)