简体   繁体   中英

variable of type kotlin.collections.List becomes java.util.Arraylist and causes error

I am trying to create an application with the walt.id API where I get an error stating the variable is expected to be of type kotlin.collections.List<kotlin.String> but it is of type java.util.ArrayList even though the variable is of the right type:

@Json(name = "@context") 
var context: List<String>? = listOf("https://www.w3.org/2018/credentials/v1"),

I'm wondering if this is a Kotlin issue or a Walt.id Api issue since its implementation is unavailable. The variable is part of a model that gets passed into a method that transforms the object:

package model

import com.beust.klaxon.Json
import id.walt.vclib.model.*
import id.walt.vclib.registry.VerifiableCredentialMetadata
import java.time.LocalDate


data class EHIC(
    @Json(name = "@context") 
    var context: List<String>? = listOf("https://www.w3.org/2018/credentials/v1"),
...

When I try to call that method that transforms the implementation of the EHIC object, I get the following error:

Exception in thread "main" com.beust.klaxon.KlaxonException: Unable to instantiate VerifiableAttestation:
    Parameter context: expected kotlin.collections.List<kotlin.String> but received java.util.ArrayList (value: [https://www.w3.org/2018/credentials/v1])
No argument provided for a required parameter: parameter #1 id of fun `<init>`(kotlin.collections.List<kotlin.String>, kotlin.String?, kotlin.String?, kotlin.String?, kotlin.String?, kotlin.String?, id.walt.vclib.credentials.VerifiableAttestation.VerifiableAttestationSubject?, id.walt.vclib.model.CredentialStatus?, id.walt.vclib.model.CredentialSchema?, kotlin.collections.List<id.walt.vclib.credentials.VerifiableAttestation.Evidence>?, id.walt.vclib.model.Proof?): id.walt.vclib.credentials.VerifiableAttestation
No argument provided for a required parameter: parameter #1 id of fun `<init>`(kotlin.collections.List<kotlin.String>, kotlin.String?, kotlin.String?, kotlin.String?, kotlin.String?, kotlin.String?, id.walt.vclib.credentials.VerifiableAttestation.VerifiableAttestationSubject?, id.walt.vclib.model.CredentialStatus?, id.walt.vclib.model.CredentialSchema?, kotlin.collections.List<id.walt.vclib.credentials.VerifiableAttestation.Evidence>?, id.walt.vclib.model.Proof?): id.walt.vclib.credentials.VerifiableAttestation
No argument provided for a required parameter: parameter #1 id of fun `<init>`(kotlin.collections.List<kotlin.String>, kotlin.String?, kotlin.String?, kotlin.String?, kotlin.String?, kotlin.String?, id.walt.vclib.credentials.VerifiableAttestation.VerifiableAttestationSubject?, id.walt.vclib.model.CredentialStatus?, id.walt.vclib.model.CredentialSchema?, kotlin.collections.List<id.walt.vclib.credentials.VerifiableAttestation.Evidence>?, id.walt.vclib.model.Proof?): id.walt.vclib.credentials.VerifiableAttestation

    at com.beust.klaxon.JsonObjectConverter.initIntoUserClass(JsonObjectConverter.kt:115)
    at com.beust.klaxon.JsonObjectConverter.fromJson(JsonObjectConverter.kt:30)
    at com.beust.klaxon.DefaultConverter.fromJsonObject(DefaultConverter.kt:223)
    at com.beust.klaxon.DefaultConverter.fromJson(DefaultConverter.kt:40)
    at com.beust.klaxon.Klaxon.fromJsonObject(Klaxon.kt:296)
    at id.walt.vclib.model.VerifiableCredential$Companion.fromString(VerifiableCredential.kt:219)
    at id.walt.vclib.model.VerifiableCredentialKt.toCredential(VerifiableCredential.kt:198)
    at ebsi.IssuerKt.issueCredentials(Issuer.kt:138)
    at ebsi.IssuerKt.credentials(Issuer.kt:34)
    at ebsi.IssuerKt.main(Issuer.kt:25)
    at ebsi.IssuerKt.main(Issuer.kt)

Process finished with exit code 1

I have also tried to write the variable as:

@Json(name = "@context") var context: kotlin.collections.List<kotlin.String> = listOf("https://www.w3.org/2018/credentials/v1"),

But it still throws the same error.

I apologize for my bad english and for being vague, I'm very exhausted and in need of sleep. Help is much appreciated, thank you.

Some additional photos that might help: 在此处输入图像描述

在此处输入图像描述

I think you should do the opposite,

@Json(name = "@context") 
var context: ArrayList<String>? = arrayListOf("https://www.w3.org/2018/credentials/v1")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM