From 918740455f71a4f9f77e65fe55422e0d956b1826 Mon Sep 17 00:00:00 2001 From: Andrew Nadraliev Date: Wed, 1 Jun 2022 13:37:41 +0500 Subject: [PATCH 1/3] Allow parser to accept all Lists, not just JSONArray (descendant of List) --- lib/src/main/kotlin/org/didcommx/didcomm/utils/JSONUtils.kt | 4 ++-- .../kotlin/org/didcommx/didcomm/fixtures/Fixtures.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/main/kotlin/org/didcommx/didcomm/utils/JSONUtils.kt b/lib/src/main/kotlin/org/didcommx/didcomm/utils/JSONUtils.kt index ff65ac0..5598901 100644 --- a/lib/src/main/kotlin/org/didcommx/didcomm/utils/JSONUtils.kt +++ b/lib/src/main/kotlin/org/didcommx/didcomm/utils/JSONUtils.kt @@ -7,7 +7,7 @@ import com.nimbusds.jose.util.JSONObjectUtils import org.didcommx.didcomm.exceptions.MalformedMessageException inline fun Map.getTypedArray(key: String): Array? = this[key]?.let { - if (it !is JSONArray) throw MalformedMessageException("The expected type of header '$key' is 'JSONArray'. Got '${it::class.simpleName}'") + if (it !is List<*>) throw MalformedMessageException("The expected type of header '$key' is 'List'. Got '${it::class.simpleName}'") else it.getTyped(key) } @@ -16,7 +16,7 @@ inline fun Map.getTyped(key: String): T? = this[key]?. else it } -inline fun JSONArray.getTyped(key: String): Array = this.map { +inline fun List<*>.getTyped(key: String): Array = this.map { when (it) { null -> null !is T -> throw MalformedMessageException("The expected type of header '$key' is '${T::class.simpleName}'. Got '${it::class.simpleName}'") diff --git a/lib/src/testCommon/kotlin/org/didcommx/didcomm/fixtures/Fixtures.kt b/lib/src/testCommon/kotlin/org/didcommx/didcomm/fixtures/Fixtures.kt index d45bb05..2d1128e 100644 --- a/lib/src/testCommon/kotlin/org/didcommx/didcomm/fixtures/Fixtures.kt +++ b/lib/src/testCommon/kotlin/org/didcommx/didcomm/fixtures/Fixtures.kt @@ -415,7 +415,7 @@ class JWM { "attachments": "131" } """.trimIndent(), - "The expected type of header 'attachments' is 'JSONArray'. Got 'String'" + "The expected type of header 'attachments' is 'List'. Got 'String'" ), WrongMessage( From 4b1605900d912ffec8ba08455b69605b511a2330 Mon Sep 17 00:00:00 2001 From: Andrew Nadraliev Date: Wed, 1 Jun 2022 13:55:05 +0500 Subject: [PATCH 2/3] Removed unused import --- lib/src/main/kotlin/org/didcommx/didcomm/utils/JSONUtils.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/main/kotlin/org/didcommx/didcomm/utils/JSONUtils.kt b/lib/src/main/kotlin/org/didcommx/didcomm/utils/JSONUtils.kt index 5598901..436cfd7 100644 --- a/lib/src/main/kotlin/org/didcommx/didcomm/utils/JSONUtils.kt +++ b/lib/src/main/kotlin/org/didcommx/didcomm/utils/JSONUtils.kt @@ -2,7 +2,6 @@ package org.didcommx.didcomm.utils import com.google.gson.GsonBuilder import com.google.gson.reflect.TypeToken -import com.nimbusds.jose.shaded.json.JSONArray import com.nimbusds.jose.util.JSONObjectUtils import org.didcommx.didcomm.exceptions.MalformedMessageException From 54e8dae75109d8e9fca42d9c3d2dc9836bc808a5 Mon Sep 17 00:00:00 2001 From: Andrew Nadraliev Date: Wed, 1 Jun 2022 14:16:36 +0500 Subject: [PATCH 3/3] Bump version to 0.3.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 2a30b3b..e1f379c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,7 +20,7 @@ android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official -version=0.3.0 +version=0.3.1 group=org.didcommx kotlinJvm=1.5.21