Skip to content

Commit 9b28905

Browse files
committed
~ fix serialization of structs with matrix abstract fields
1 parent dacd487 commit 9b28905

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

opc-ua-sdk/sdk-core/src/main/java/org/eclipse/milo/opcua/sdk/core/types/DynamicStructCodec.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,18 @@ private Object decodeFieldValue(UaDecoder decoder, StructureField field) {
331331
break;
332332
}
333333
case STRUCT:
334-
value = decoder.decodeStructMatrix(fieldName, dataTypeId);
334+
if (dataTypeId.equals(NodeIds.Structure) || fieldAllowsSubtyping(field)) {
335+
Matrix matrix = decoder.decodeMatrix(fieldName, BuiltinDataType.ExtensionObject);
336+
337+
value =
338+
matrix.transform(
339+
o -> {
340+
ExtensionObject xo = (ExtensionObject) o;
341+
return xo.decode(decoder.getEncodingContext());
342+
});
343+
} else {
344+
value = decoder.decodeStructMatrix(fieldName, dataTypeId);
345+
}
335346
break;
336347
default:
337348
throw new RuntimeException("codecType: " + typeHint);
@@ -419,7 +430,18 @@ private void encodeFieldValue(UaEncoder encoder, StructureField field, Object va
419430
encoder.encodeEnumMatrix(fieldName, matrix);
420431
break;
421432
case STRUCT:
422-
encoder.encodeStructMatrix(fieldName, matrix, dataTypeId);
433+
if (dataTypeId.equals(NodeIds.Structure) || fieldAllowsSubtyping(field)) {
434+
Matrix xoMatrix =
435+
matrix.transform(
436+
o -> {
437+
DynamicStruct structValue = (DynamicStruct) o;
438+
return ExtensionObject.encode(encoder.getEncodingContext(), structValue);
439+
});
440+
441+
encoder.encodeMatrix(fieldName, xoMatrix);
442+
} else {
443+
encoder.encodeStructMatrix(fieldName, matrix, dataTypeId);
444+
}
423445
break;
424446
default:
425447
throw new RuntimeException("codecType: " + typeHint);

0 commit comments

Comments
 (0)