|
16 | 16 | */
|
17 | 17 | package org.eclipse.digitaltwin.aas4j.v3.dataformat.xml.internal.deserialization;
|
18 | 18 |
|
| 19 | +import java.io.IOException; |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.List; |
| 22 | + |
| 23 | +import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable; |
| 24 | +import org.slf4j.Logger; |
| 25 | +import org.slf4j.LoggerFactory; |
| 26 | + |
19 | 27 | import com.fasterxml.jackson.core.JsonParser;
|
20 | 28 | import com.fasterxml.jackson.core.JsonProcessingException;
|
21 | 29 | import com.fasterxml.jackson.databind.DeserializationContext;
|
22 | 30 | import com.fasterxml.jackson.databind.JsonDeserializer;
|
23 | 31 | import com.fasterxml.jackson.databind.JsonNode;
|
24 | 32 | import com.fasterxml.jackson.databind.node.ArrayNode;
|
25 | 33 | import com.fasterxml.jackson.databind.node.ObjectNode;
|
26 |
| -import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable; |
27 |
| - |
28 |
| -import java.io.IOException; |
29 |
| -import java.util.Collections; |
30 |
| -import java.util.List; |
| 34 | +import com.google.common.collect.Lists; |
31 | 35 |
|
32 | 36 |
|
33 | 37 | public class OperationVariableDeserializer extends JsonDeserializer<List<OperationVariable>> {
|
| 38 | + private static Logger logger = LoggerFactory.getLogger(OperationVariableDeserializer.class); |
34 | 39 |
|
35 | 40 | @Override
|
36 | 41 | public List<OperationVariable> deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
37 |
| - ObjectNode node = DeserializationHelper.getRootObjectNode(parser); |
| 42 | + try { |
| 43 | + ObjectNode node = DeserializationHelper.getRootObjectNode(parser); |
38 | 44 |
|
39 |
| - if (!node.has("operationVariable")) { |
40 |
| - return Collections.emptyList(); |
| 45 | + if (!node.has("operationVariable")) { |
| 46 | + return new ArrayList<>(); |
| 47 | + } |
| 48 | + JsonNode operationVariableNode = node.get("operationVariable"); |
| 49 | + if (operationVariableNode.isArray()) { |
| 50 | + return createOperationVariablesFromArrayNode(parser, node); |
| 51 | + } else { |
| 52 | + OperationVariable operationVariable = DeserializationHelper.createInstanceFromNode(parser, operationVariableNode, OperationVariable.class); |
| 53 | + return Lists.newArrayList(operationVariable); |
| 54 | + } |
| 55 | + } catch (ClassCastException e) { |
| 56 | + logger.info("Found empty list item in Operation (e.g., '<outputVariables />') in XML. This is most likely an error."); |
| 57 | + return new ArrayList<>(); |
41 | 58 | }
|
42 |
| - JsonNode operationVariableNode = node.get("operationVariable"); |
43 |
| - if (operationVariableNode.isArray()) { |
44 |
| - return createOperationVariablesFromArrayNode(parser, node); |
45 |
| - } else { |
46 |
| - OperationVariable operationVariable = DeserializationHelper.createInstanceFromNode(parser, operationVariableNode, OperationVariable.class); |
47 |
| - return Collections.singletonList(operationVariable); |
48 |
| - } |
49 |
| - |
50 | 59 | }
|
51 | 60 |
|
52 | 61 |
|
|
0 commit comments