|
16 | 16 | package com.hivemq.edge.adapters.opcua.mqtt2opcua; |
17 | 17 |
|
18 | 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | +import com.fasterxml.jackson.databind.node.ArrayNode; |
19 | 20 | import com.google.common.io.BaseEncoding; |
20 | 21 | import org.apache.commons.lang3.NotImplementedException; |
21 | 22 | import org.eclipse.milo.opcua.binaryschema.AbstractCodec; |
|
46 | 47 | import org.slf4j.Logger; |
47 | 48 | import org.slf4j.LoggerFactory; |
48 | 49 |
|
| 50 | +import java.lang.reflect.Array; |
49 | 51 | import java.lang.reflect.Field; |
50 | 52 | import java.time.Instant; |
| 53 | +import java.util.ArrayList; |
| 54 | +import java.util.Arrays; |
51 | 55 | import java.util.Date; |
| 56 | +import java.util.List; |
52 | 57 | import java.util.Map; |
53 | 58 | import java.util.Optional; |
54 | 59 | import java.util.UUID; |
@@ -110,7 +115,11 @@ public JsonToOpcUAConverter(final @NotNull OpcUaClient client) throws UaExceptio |
110 | 115 | rootNode); |
111 | 116 |
|
112 | 117 | if (builtinType != BuiltinDataType.ExtensionObject) { |
113 | | - return parsetoOpcUAObject(builtinType, rootNode); |
| 118 | + if(rootNode.isArray()) { |
| 119 | + return generateArrayFromArrayNode((ArrayNode) rootNode, builtinType); |
| 120 | + } else { |
| 121 | + return parsetoOpcUAObject(builtinType, rootNode); |
| 122 | + } |
114 | 123 | } |
115 | 124 |
|
116 | 125 | final NodeId binaryEncodingId = dataType.getBinaryEncodingId(); |
@@ -575,4 +584,18 @@ static boolean extractBoolean(final JsonNode jsonNode) { |
575 | 584 | intendedClass + |
576 | 585 | "due to underflow."); |
577 | 586 | } |
| 587 | + |
| 588 | + private Object[] generateArrayFromArrayNode(final @NotNull ArrayNode arrayNode, final @NotNull BuiltinDataType type) { |
| 589 | + Object[] ret = (Object[])Array.newInstance(type.getBackingClass(), arrayNode.size()); |
| 590 | + |
| 591 | + for (int i = 0; i < arrayNode.size(); i++) { |
| 592 | + JsonNode arrayEntry = arrayNode.get(i); |
| 593 | + if (arrayEntry.isArray()) { |
| 594 | + ret[i] = generateArrayFromArrayNode((ArrayNode) arrayEntry, type); |
| 595 | + } else { |
| 596 | + ret[i] = parsetoOpcUAObject(type, arrayEntry); |
| 597 | + } |
| 598 | + } |
| 599 | + return ret; |
| 600 | + } |
578 | 601 | } |
0 commit comments