diff --git a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/DataElementsDeserializer.java b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/DataElementsDeserializer.java index c2fd58d4..4c259b45 100644 --- a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/DataElementsDeserializer.java +++ b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/DataElementsDeserializer.java @@ -28,7 +28,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -47,7 +46,7 @@ public DataElementsDeserializer() { public List deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { TreeNode treeNode = DeserializationHelper.getRootTreeNode(parser); if (treeNode instanceof TextNode) { - return Collections.emptyList(); + return new ArrayList<>(); } ObjectNode node = (ObjectNode) treeNode; diff --git a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/NoEntryWrapperListDeserializer.java b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/NoEntryWrapperListDeserializer.java index 81cfb79e..550a2fe3 100644 --- a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/NoEntryWrapperListDeserializer.java +++ b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/NoEntryWrapperListDeserializer.java @@ -17,7 +17,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.slf4j.Logger; @@ -30,6 +29,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.collect.Lists; /** * Custom deserializer for lists without individual list entry wrappers for parametrized classes. @@ -57,7 +57,7 @@ public List deserialize(JsonParser parser, DeserializationContext ctxt) throw return createEntriesFromArrayNode((ArrayNode) langStringNode, parser); } } catch (ClassCastException e) { - logger.info("Found empty list items (e.g., '' of dataSpecificationIec61360) in XML. This is most likely an error."); + logger.info("Found empty list item (e.g., '' of dataSpecificationIec61360) in XML. This is most likely an error."); return new ArrayList(); } } @@ -73,6 +73,6 @@ private List createEntriesFromArrayNode(ArrayNode langStringsNode, JsonParser private List createEntriesFromObjectNode(JsonNode langStringNode, JsonParser parser) throws IOException { T entry = nodeDeserializer.readValue(langStringNode, parser); - return Collections.singletonList(entry); + return Lists.newArrayList(entry); } } diff --git a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/OperationVariableDeserializer.java b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/OperationVariableDeserializer.java index d2c970aa..a67fbd3f 100644 --- a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/OperationVariableDeserializer.java +++ b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/OperationVariableDeserializer.java @@ -16,6 +16,14 @@ */ package org.eclipse.digitaltwin.aas4j.v3.dataformat.xml.internal.deserialization; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; @@ -23,30 +31,31 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable; - -import java.io.IOException; -import java.util.Collections; -import java.util.List; +import com.google.common.collect.Lists; public class OperationVariableDeserializer extends JsonDeserializer> { + private static Logger logger = LoggerFactory.getLogger(OperationVariableDeserializer.class); @Override public List deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { - ObjectNode node = DeserializationHelper.getRootObjectNode(parser); + try { + ObjectNode node = DeserializationHelper.getRootObjectNode(parser); - if (!node.has("operationVariable")) { - return Collections.emptyList(); + if (!node.has("operationVariable")) { + return new ArrayList<>(); + } + JsonNode operationVariableNode = node.get("operationVariable"); + if (operationVariableNode.isArray()) { + return createOperationVariablesFromArrayNode(parser, node); + } else { + OperationVariable operationVariable = DeserializationHelper.createInstanceFromNode(parser, operationVariableNode, OperationVariable.class); + return Lists.newArrayList(operationVariable); + } + } catch (ClassCastException e) { + logger.info("Found empty list item in Operation (e.g., '') in XML. This is most likely an error."); + return new ArrayList<>(); } - JsonNode operationVariableNode = node.get("operationVariable"); - if (operationVariableNode.isArray()) { - return createOperationVariablesFromArrayNode(parser, node); - } else { - OperationVariable operationVariable = DeserializationHelper.createInstanceFromNode(parser, operationVariableNode, OperationVariable.class); - return Collections.singletonList(operationVariable); - } - } diff --git a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/QualifierDeserializer.java b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/QualifierDeserializer.java index cb6d251e..5f9cffa9 100644 --- a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/QualifierDeserializer.java +++ b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/QualifierDeserializer.java @@ -41,6 +41,14 @@ */ package org.eclipse.digitaltwin.aas4j.v3.dataformat.xml.internal.deserialization; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.Qualifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; @@ -48,28 +56,31 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.eclipse.digitaltwin.aas4j.v3.model.Qualifier; - -import java.io.IOException; -import java.util.Collections; -import java.util.List; - +import com.google.common.collect.Lists; public class QualifierDeserializer extends JsonDeserializer> { + private static Logger logger = LoggerFactory.getLogger(QualifierDeserializer.class); + @Override public List deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { - ObjectNode node = DeserializationHelper.getRootObjectNode(parser); + try { + ObjectNode node = DeserializationHelper.getRootObjectNode(parser); - if (!node.has("qualifier")) { - return Collections.emptyList(); - } - JsonNode qualifierNode = node.get("qualifier"); - if (qualifierNode.isArray()) { - return createConstraintsFromArrayNode(parser, node); - } else { - Qualifier qualifier = DeserializationHelper.createInstanceFromNode(parser, qualifierNode, Qualifier.class); - return Collections.singletonList(qualifier); + if (!node.has("qualifier")) { + return new ArrayList<>(); + } + JsonNode qualifierNode = node.get("qualifier"); + if (qualifierNode.isArray()) { + return createConstraintsFromArrayNode(parser, node); + } else { + Qualifier qualifier = DeserializationHelper.createInstanceFromNode(parser, qualifierNode, + Qualifier.class); + return Lists.newArrayList(qualifier); + } + } catch (ClassCastException e) { + logger.info("Found empty list item of qualifiers ('') in XML. This is most likely an error."); + return new ArrayList(); } } diff --git a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/ReferencesDeserializer.java b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/ReferencesDeserializer.java index 7c927e01..df02b914 100644 --- a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/ReferencesDeserializer.java +++ b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/ReferencesDeserializer.java @@ -15,6 +15,12 @@ */ package org.eclipse.digitaltwin.aas4j.v3.dataformat.xml.internal.deserialization; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.TreeNode; @@ -22,19 +28,14 @@ import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import com.google.common.collect.Lists; public class ReferencesDeserializer extends JsonDeserializer> { @Override public List deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { TreeNode treeNode = DeserializationHelper.getRootTreeNode(parser); - treeNode = treeNode.get("reference"); + treeNode = treeNode.get("reference"); if (treeNode.isArray()) { return createReferencesFromArray(parser, (ArrayNode) treeNode); } else { @@ -44,7 +45,7 @@ public List deserialize(JsonParser parser, DeserializationContext ctx private List createReferencesFromObjectNode(JsonParser parser, ObjectNode node) throws IOException { Reference reference = createReference(parser, node); - return Collections.singletonList(reference); + return Lists.newArrayList(reference); } private List createReferencesFromArray(JsonParser parser, ArrayNode arrayNode) throws IOException { diff --git a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/SubmodelElementsDeserializer.java b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/SubmodelElementsDeserializer.java index 0fd407cb..e77e85e9 100644 --- a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/SubmodelElementsDeserializer.java +++ b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/internal/deserialization/SubmodelElementsDeserializer.java @@ -29,7 +29,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -48,14 +47,14 @@ public SubmodelElementsDeserializer() { public List deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { TreeNode treeNode = DeserializationHelper.getRootTreeNode(parser); if (treeNode instanceof TextNode) { - return Collections.emptyList(); + return new ArrayList<>(); } else { return createSubmodelElements(parser, ctxt, treeNode); } } private List createSubmodelElements(JsonParser parser, DeserializationContext ctxt, TreeNode treeNode) throws IOException, JsonProcessingException { - if (treeNode.isArray()) { + if (treeNode.isArray()) { return getSubmodelElementsFromArrayNode(parser, ctxt, (ArrayNode) treeNode); } else { return getSubmodelElementsFromObjectNode(parser, ctxt, (JsonNode) treeNode); @@ -100,7 +99,7 @@ private List getSubmodelElementsFromArrayNode(JsonParser parser private SubmodelElement getSubmodelElementFromJsonNode(JsonParser parser, DeserializationContext ctxt, JsonNode nodeSubmodelElement) throws IOException, JsonProcessingException { JsonParser parserReference = parser.getCodec().getFactory().getCodec().treeAsTokens(nodeSubmodelElement); - return deserializer.deserialize(parserReference, ctxt); + return deserializer.deserialize(parserReference, ctxt); } }