danielgerlag / danielgerlag/jworkflow

Can I use ArrayList in Data?

Open
#15 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
122
Forks
35
PR merge metrics
No merged PRs in 30d

Description

Hello, I want to show each data in ArrayList with foreach loop with using json file. This is my json file

```
{
"id": "test-workflow",
"version": 1,
"dataType": "io.blt.MyData",
"steps": [
{
"id": "step1",
"stepType": "io.steps.Hello",
"nextStepId": "step2"
},
{
"id": "step2",
"stepType": "net.jworkflow.primitives.Foreach",
"nextStepId": "step3",
"inputs": {
"collection": "data.values.toArray(new Object[0])"
},
"thenDo": [
[
{
"id": "step2.1",
"stepType": "io.steps.PrintMessage",
"inputs": {
"message": "'doing 2.1' + data.values.toArray(new Object[0])[step.index]"
}
}
]
]
},
{
"id": "step3",
"stepType": "io.steps.Goodbye"
}
]
}

```

MyData class is

```
public class MyData {
public int value1;
public int value2;
public int value3;
public List values = new ArrayList<>();
public Object[] collection1;
}

```

and PrintMessage class is

```

public class PrintMessage implements StepBody {

public String message;
public int index;

@Override
public ExecutionResult run(StepExecutionContext context) {
System.out.println(message);
index++;
return ExecutionResult.next();
}
}

```

Error:
```
java.lang.RuntimeException: javax.script.ScriptException: TypeError: Object[0] is not a function in at line number 1

```

when I use primitive array instade of ArrayList then It works. But I want to use ArrayList. Can I use?
One more thing, Can I get each value of the array without declare extra index in PrintMessage class.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.