diff --git a/dataformat-xml/pom.xml b/dataformat-xml/pom.xml index 4ed49f74a..66680ae23 100644 --- a/dataformat-xml/pom.xml +++ b/dataformat-xml/pom.xml @@ -61,7 +61,6 @@ org.slf4j slf4j-api - test ${project.groupId} @@ -71,5 +70,10 @@ com.fasterxml.jackson.core jackson-core + + org.slf4j + slf4j-simple + test + diff --git a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/deserialization/NoEntryWrapperListDeserializer.java b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/deserialization/NoEntryWrapperListDeserializer.java index 3134a00a4..320ea53f0 100644 --- a/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/deserialization/NoEntryWrapperListDeserializer.java +++ b/dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/deserialization/NoEntryWrapperListDeserializer.java @@ -15,6 +15,14 @@ */ package org.eclipse.digitaltwin.aas4j.v3.dataformat.xml.deserialization; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +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,19 +31,15 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - /** * Custom deserializer for lists without individual list entry wrappers for parametrized classes. * * @param deserialized class within the list */ -public class NoEntryWrapperListDeserializer extends JsonDeserializer> { +public class NoEntryWrapperListDeserializer extends JsonDeserializer> { protected final String elementName; private CustomJsonNodeDeserializer nodeDeserializer; + private static Logger logger = LoggerFactory.getLogger(NoEntryWrapperListDeserializer.class); public NoEntryWrapperListDeserializer(String elementName, CustomJsonNodeDeserializer nodeDeserializer) { this.elementName = elementName; @@ -44,12 +48,17 @@ public NoEntryWrapperListDeserializer(String elementName, CustomJsonNodeDeserial @Override public List deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { - ObjectNode node = DeserializationHelper.getRootObjectNode(parser); - JsonNode langStringNode = node.get(elementName); - if (langStringNode.isObject()) { - return createEntriesFromObjectNode(langStringNode, parser); - } else { - return createEntriesFromArrayNode((ArrayNode) langStringNode, parser); + try { + ObjectNode node = DeserializationHelper.getRootObjectNode(parser); + JsonNode langStringNode = node.get(elementName); + if (langStringNode.isObject()) { + return createEntriesFromObjectNode(langStringNode, parser); + } else { + 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."); + return new ArrayList(); } } diff --git a/dataformat-xml/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/XMLDeserializerTest.java b/dataformat-xml/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/XMLDeserializerTest.java index f3d698768..db1ba2ec6 100644 --- a/dataformat-xml/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/XMLDeserializerTest.java +++ b/dataformat-xml/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/XMLDeserializerTest.java @@ -15,6 +15,9 @@ */ package org.eclipse.digitaltwin.aas4j.v3.dataformat.xml; +import java.io.FileNotFoundException; +import java.util.List; + import org.eclipse.digitaltwin.aas4j.v3.dataformat.DeserializationException; import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException; import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.AASFull; @@ -30,9 +33,6 @@ import org.junit.Test; import org.xml.sax.SAXException; -import java.io.FileNotFoundException; -import java.util.List; - public class XMLDeserializerTest { @Test @@ -133,4 +133,10 @@ public void deserializeAASWithExtensionMaximal() throws SerializationException, Assert.assertEquals(Examples.EXTENSION_MAXIMAL, env); } + + @Test + public void deserializeWithEmptyKeys() throws FileNotFoundException, DeserializationException { + java.io.File file = new java.io.File("src/test/resources/empty_entries.xml"); + new XmlDeserializer().read(file); + } } diff --git a/dataformat-xml/src/test/resources/empty_entries.xml b/dataformat-xml/src/test/resources/empty_entries.xml new file mode 100644 index 000000000..255b2c71a --- /dev/null +++ b/dataformat-xml/src/test/resources/empty_entries.xml @@ -0,0 +1,88 @@ + + + + Nameplate + https://example.com/ids/sm/2593_9052_1042_2364 + Template + + ExternalReference + + + GlobalReference + https://admin-shell.io/zvei/nameplate/2/0/Nameplate + + + + + + ManufacturerName + + + en + Note: see also [IRDI] 0112/2///61987#ABA565#007 manufacturer Note: mandatory property according to EU Machine Directive 2006/42/EC. + + + + ExternalReference + + + GlobalReference + 0173-1#02-AAO677#002 + + + + + + Multiplicity + xs:string + One + + + + + + ExternalReference + + + GlobalReference + http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/3/0 + + + + + + + + + + + + ModelReference + + + + + + + + + + + + de + Muster AG + + + en + Muster AG + + + + ExternalReference + + + + + + + \ No newline at end of file