Skip to content

Can I use ArrayList in Data? #15

@masa2146

Description

@masa2146

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<Object> 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 <eval> 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions