Use JsonNodeUtils to manage array nodes

This commit is contained in:
Xavi Aracil 2022-11-25 08:28:02 +01:00
parent 543a2c5bdb
commit 40b34cce13
2 changed files with 15 additions and 14 deletions

View File

@ -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;
@ -69,9 +70,11 @@ public class Assertion extends Credential {
public static Assertion.Type valueOf (JsonNode typeNode) {
if(typeNode != null) {
String value = typeNode.asText();
List<String> values = JsonNodeUtil.asStringList(typeNode);
for (String value : values) {
if(value.equals("Assertion")) {
return Assertion;
}
}
}
return Unknown;

View File

@ -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<String, SchemaKey> 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<JsonNode> iter = typeArray.iterator();
while(iter.hasNext()) {
String value = iter.next().asText();
public static VerifiableCredential.Type valueOf (JsonNode typeNode) {
if(typeNode != null) {
List<String> values = JsonNodeUtil.asStringList(typeNode);
for (String value : values) {
if(value.equals("AchievementCredential") || value.equals("OpenBadgeCredential")) {
return AchievementCredential;
} else if(value.equals("ClrCredential")) {