diff --git a/examples/12-example-byte-manipulation.yaml b/examples/12-example-byte-manipulation.yaml index 9973b6fa..7bad4b34 100644 --- a/examples/12-example-byte-manipulation.yaml +++ b/examples/12-example-byte-manipulation.yaml @@ -30,7 +30,7 @@ functions: code: | global newSchemaId log.info("Replacing schema in message value: {}", value) - if value is not None: + if isinstance(value, list): if value[0] == 0 and len(value) >= 5: value[1] = (newSchemaId & 0xff000000) >> 24 value[2] = (newSchemaId & 0xff0000) >> 16 diff --git a/ksml/src/main/java/io/axual/ksml/python/PythonDataObjectMapper.java b/ksml/src/main/java/io/axual/ksml/python/PythonDataObjectMapper.java index fca42e17..6fd5c830 100644 --- a/ksml/src/main/java/io/axual/ksml/python/PythonDataObjectMapper.java +++ b/ksml/src/main/java/io/axual/ksml/python/PythonDataObjectMapper.java @@ -28,6 +28,7 @@ import io.axual.ksml.util.ExecutionUtil; import org.graalvm.polyglot.Value; +import java.util.ArrayList; import java.util.Map; public class PythonDataObjectMapper extends NativeDataObjectMapper { @@ -146,7 +147,13 @@ public Value fromDataObject(DataObject object) { if (object instanceof DataLong val) return Value.asValue(val.value()); if (object instanceof DataFloat val) return Value.asValue(val.value()); if (object instanceof DataDouble val) return Value.asValue(val.value()); - if (object instanceof DataBytes val) return Value.asValue(val.value()); + if (object instanceof DataBytes val) { + // Convert the contained byte array to a list, so it can be converted to a Python list by the PythonFunction + // wrapper code downstream... + final var bytes = new ArrayList(val.value().length); + for (byte b : val.value()) bytes.add(b); + return Value.asValue(bytes); + } if (object instanceof DataString val) return Value.asValue(val.value()); if (object instanceof DataList val) return Value.asValue(fromDataList(val)); if (object instanceof DataStruct val) return Value.asValue(fromDataStruct(val));