diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java index 193a3f0..9bfab9a 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java @@ -7,6 +7,7 @@ import java.util.stream.Collectors; import org.oneedtech.inspect.schema.Catalog; import org.oneedtech.inspect.schema.SchemaKey; import org.oneedtech.inspect.util.resource.Resource; +import org.oneedtech.inspect.vc.util.JsonNodeUtil; import com.fasterxml.jackson.databind.JsonNode; import com.google.common.base.MoreObjects; @@ -25,7 +26,7 @@ public class Assertion extends Credential { super(ID, resource, data, jwt, schemas); JsonNode typeNode = jsonData.get("type"); - this.assertionType = Assertion.Type.valueOf(typeNode); + this.assertionType = Assertion.Type.valueOf(typeNode); } @Override @@ -69,13 +70,15 @@ public class Assertion extends Credential { public static Assertion.Type valueOf (JsonNode typeNode) { if(typeNode != null) { - String value = typeNode.asText(); - if(value.equals("Assertion")) { - return Assertion; + List values = JsonNodeUtil.asStringList(typeNode); + for (String value : values) { + if(value.equals("Assertion")) { + return Assertion; + } } } return Unknown; - } + } } public static final String ID = Assertion.class.getCanonicalName(); diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java index 60f48a0..b9443c6 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java @@ -5,7 +5,6 @@ import static org.oneedtech.inspect.vc.VerifiableCredential.Type.ClrCredential; import static org.oneedtech.inspect.vc.VerifiableCredential.Type.EndorsementCredential; import static org.oneedtech.inspect.vc.VerifiableCredential.Type.VerifiablePresentation; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -14,9 +13,9 @@ import java.util.stream.Collectors; import org.oneedtech.inspect.schema.Catalog; import org.oneedtech.inspect.schema.SchemaKey; import org.oneedtech.inspect.util.resource.Resource; +import org.oneedtech.inspect.vc.util.JsonNodeUtil; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; @@ -31,7 +30,7 @@ public class VerifiableCredential extends Credential { protected VerifiableCredential(Resource resource, JsonNode data, String jwt, Map schemas) { super(ID, resource, data, jwt, schemas); - ArrayNode typeNode = (ArrayNode)jsonData.get("type"); + JsonNode typeNode = jsonData.get("type"); this.credentialType = VerifiableCredential.Type.valueOf(typeNode); } @@ -82,11 +81,10 @@ public class VerifiableCredential extends Credential { VerifiableCredential, //this is an underspecifier in our context Unknown; - public static VerifiableCredential.Type valueOf (ArrayNode typeArray) { - if(typeArray != null) { - Iterator iter = typeArray.iterator(); - while(iter.hasNext()) { - String value = iter.next().asText(); + public static VerifiableCredential.Type valueOf (JsonNode typeNode) { + if(typeNode != null) { + List values = JsonNodeUtil.asStringList(typeNode); + for (String value : values) { if(value.equals("AchievementCredential") || value.equals("OpenBadgeCredential")) { return AchievementCredential; } else if(value.equals("ClrCredential")) { @@ -99,7 +97,7 @@ public class VerifiableCredential extends Credential { } } return Unknown; - } + } } public enum ProofType {