Skip to content

Ensure not workflowmodel is returned within a Map or Collection #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

public class JavaModel implements WorkflowModel {
class JavaModel implements WorkflowModel {

private Object object;

Expand All @@ -33,7 +35,7 @@ public class JavaModel implements WorkflowModel {
static final JavaModel NullModel = new JavaModel(null);

JavaModel(Object object) {
this.object = object;
this.object = asJavaObject(object);
}

@Override
Expand Down Expand Up @@ -89,6 +91,20 @@ public Object asJavaObject() {
return object;
}

static Object asJavaObject(Object object) {
if (object instanceof WorkflowModel model) {
return model.asJavaObject();
} else if (object instanceof Map map) {
return ((Map<String, Object>) map)
.entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, e -> asJavaObject(e.getValue())));
} else if (object instanceof Collection col) {
return col.stream().map(JavaModel::asJavaObject).collect(Collectors.toList());
} else {
return object;
}
}

@Override
public Object asIs() {
return object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Iterator;
import java.util.Optional;

public class JavaModelCollection implements Collection<WorkflowModel>, WorkflowModelCollection {
class JavaModelCollection implements Collection<WorkflowModel>, WorkflowModelCollection {

private final Collection object;

Expand All @@ -31,7 +31,7 @@ public class JavaModelCollection implements Collection<WorkflowModel>, WorkflowM
}

JavaModelCollection(Collection<?> object) {
this.object = object;
this.object = (Collection) JavaModel.asJavaObject(object);
}

@Override
Expand Down Expand Up @@ -86,12 +86,12 @@ public <T> T[] toArray(T[] a) {

@Override
public boolean add(WorkflowModel e) {
return object.add(e.asIs());
return object.add(e.asJavaObject());
}

@Override
public boolean remove(Object o) {
return object.remove(((WorkflowModel) o).asIs());
return object.remove(((WorkflowModel) o).asJavaObject());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.time.OffsetDateTime;
import java.util.Map;

public class JavaModelFactory implements WorkflowModelFactory {
class JavaModelFactory implements WorkflowModelFactory {

@Override
public WorkflowModel combine(Map<String, WorkflowModel> workflowVariables) {
Expand Down