Skip to content

[Fix #636] Refactor to separate Jackson/JQ from core #642

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 2 commits into from
Jul 17, 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
2 changes: 1 addition & 1 deletion examples/events/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<dependencies>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-core</artifactId>
<artifactId>serverlessworkflow-impl-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
5 changes: 5 additions & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
<artifactId>serverlessworkflow-impl-http</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-jackson</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/simpleGet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<dependencies>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-core</artifactId>
<artifactId>serverlessworkflow-impl-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.serverlessworkflow</groupId>
Expand Down
22 changes: 7 additions & 15 deletions impl/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,23 @@
<artifactId>serverlessworkflow-impl-core</artifactId>
<name>Serverless Workflow :: Impl :: Core</name>
<dependencies>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-api</artifactId>
<version>${project.version}</version>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-types</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-api</artifactId>
<artifactId>cloudevents-core</artifactId>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-json-jackson</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.github.f4b6a3</groupId>
<artifactId>ulid-creator</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
</dependency>
<dependency>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package io.serverlessworkflow.impl;

import com.fasterxml.jackson.databind.JsonNode;
import io.serverlessworkflow.api.types.TaskBase;
import io.serverlessworkflow.impl.executors.TransitionInfo;
import java.time.Instant;
Expand All @@ -25,22 +24,22 @@

public class TaskContext {

private final JsonNode rawInput;
private final WorkflowModel rawInput;
private final TaskBase task;
private final WorkflowPosition position;
private final Instant startedAt;
private final String taskName;
private final Map<String, Object> contextVariables;
private final Optional<TaskContext> parentContext;

private JsonNode input;
private JsonNode output;
private JsonNode rawOutput;
private WorkflowModel input;
private WorkflowModel output;
private WorkflowModel rawOutput;
private Instant completedAt;
private TransitionInfo transition;

public TaskContext(
JsonNode input,
WorkflowModel input,
WorkflowPosition position,
Optional<TaskContext> parentContext,
String taskName,
Expand All @@ -49,15 +48,15 @@ public TaskContext(
}

private TaskContext(
JsonNode rawInput,
WorkflowModel rawInput,
Optional<TaskContext> parentContext,
String taskName,
TaskBase task,
WorkflowPosition position,
Instant startedAt,
JsonNode input,
JsonNode output,
JsonNode rawOutput) {
WorkflowModel input,
WorkflowModel output,
WorkflowModel rawOutput) {
this.rawInput = rawInput;
this.parentContext = parentContext;
this.taskName = taskName;
Expand All @@ -76,40 +75,40 @@ public TaskContext copy() {
rawInput, parentContext, taskName, task, position, startedAt, input, output, rawOutput);
}

public void input(JsonNode input) {
public void input(WorkflowModel input) {
this.input = input;
this.rawOutput = input;
this.output = input;
}

public JsonNode input() {
public WorkflowModel input() {
return input;
}

public JsonNode rawInput() {
public WorkflowModel rawInput() {
return rawInput;
}

public TaskBase task() {
return task;
}

public TaskContext rawOutput(JsonNode output) {
public TaskContext rawOutput(WorkflowModel output) {
this.rawOutput = output;
this.output = output;
return this;
}

public JsonNode rawOutput() {
public WorkflowModel rawOutput() {
return rawOutput;
}

public TaskContext output(JsonNode output) {
public TaskContext output(WorkflowModel output) {
this.output = output;
return this;
}

public JsonNode output() {
public WorkflowModel output() {
return output;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@

import com.github.f4b6a3.ulid.UlidCreator;
import io.serverlessworkflow.api.types.Document;
import io.serverlessworkflow.api.types.SchemaInline;
import io.serverlessworkflow.api.types.Workflow;
import io.serverlessworkflow.impl.events.EventConsumer;
import io.serverlessworkflow.impl.events.EventPublisher;
import io.serverlessworkflow.impl.events.InMemoryEvents;
import io.serverlessworkflow.impl.executors.DefaultTaskExecutorFactory;
import io.serverlessworkflow.impl.executors.TaskExecutorFactory;
import io.serverlessworkflow.impl.expressions.ExpressionFactory;
import io.serverlessworkflow.impl.expressions.JQExpressionFactory;
import io.serverlessworkflow.impl.expressions.RuntimeDescriptor;
import io.serverlessworkflow.impl.jsonschema.DefaultSchemaValidatorFactory;
import io.serverlessworkflow.impl.jsonschema.SchemaValidatorFactory;
import io.serverlessworkflow.impl.resources.DefaultResourceLoaderFactory;
import io.serverlessworkflow.impl.resources.ResourceLoaderFactory;
import io.serverlessworkflow.impl.resources.StaticResource;
import io.serverlessworkflow.impl.schema.SchemaValidator;
import io.serverlessworkflow.impl.schema.SchemaValidatorFactory;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -101,11 +103,31 @@ public WorkflowIdFactory idFactory() {
}

public static class Builder {
private static final SchemaValidatorFactory EMPTY_SCHEMA_VALIDATOR =
new SchemaValidatorFactory() {

private final SchemaValidator NoValidation =
new SchemaValidator() {
@Override
public void validate(WorkflowModel node) {}
};

@Override
public SchemaValidator getValidator(StaticResource resource) {

return NoValidation;
}

@Override
public SchemaValidator getValidator(SchemaInline inline) {
return NoValidation;
}
};
private TaskExecutorFactory taskFactory = DefaultTaskExecutorFactory.get();
private ExpressionFactory exprFactory = JQExpressionFactory.get();
private ExpressionFactory exprFactory;
private Collection<WorkflowExecutionListener> listeners;
private ResourceLoaderFactory resourceLoaderFactory = DefaultResourceLoaderFactory.get();
private SchemaValidatorFactory schemaValidatorFactory = DefaultSchemaValidatorFactory.get();
private SchemaValidatorFactory schemaValidatorFactory;
private WorkflowPositionFactory positionFactory = () -> new QueueWorkflowPosition();
private WorkflowIdFactory idFactory = () -> UlidCreator.getMonotonicUlid().toString();
private ExecutorServiceFactory executorFactory = () -> Executors.newCachedThreadPool();
Expand Down Expand Up @@ -175,6 +197,18 @@ public Builder withEventPublisher(EventPublisher eventPublisher) {
}

public WorkflowApplication build() {
if (exprFactory == null) {
exprFactory =
ServiceLoader.load(ExpressionFactory.class)
.findFirst()
.orElseThrow(() -> new IllegalStateException("Expression factory is required"));
}
if (schemaValidatorFactory == null) {
schemaValidatorFactory =
ServiceLoader.load(SchemaValidatorFactory.class)
.findFirst()
.orElse(EMPTY_SCHEMA_VALIDATOR);
}
return new WorkflowApplication(this);
}
}
Expand Down Expand Up @@ -202,6 +236,10 @@ public WorkflowPositionFactory positionFactory() {
return positionFactory;
}

public WorkflowModelFactory modelFactory() {
return exprFactory.modelFactory();
}

public RuntimeDescriptorFactory runtimeDescriptorFactory() {
return runtimeDescriptorFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
*/
package io.serverlessworkflow.impl;

import com.fasterxml.jackson.databind.JsonNode;

public class WorkflowContext {
private final WorkflowDefinition definition;
private final WorkflowInstance instance;
private JsonNode context;
private WorkflowModel context;

WorkflowContext(WorkflowDefinition definition, WorkflowInstance instance) {
this.definition = definition;
Expand All @@ -31,11 +29,11 @@ public WorkflowInstance instance() {
return instance;
}

public JsonNode context() {
public WorkflowModel context() {
return context;
}

public void context(JsonNode context) {
public void context(WorkflowModel context) {
this.context = context;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
import io.serverlessworkflow.api.types.Workflow;
import io.serverlessworkflow.impl.executors.TaskExecutor;
import io.serverlessworkflow.impl.executors.TaskExecutorHelper;
import io.serverlessworkflow.impl.json.JsonUtils;
import io.serverlessworkflow.impl.jsonschema.SchemaValidator;
import io.serverlessworkflow.impl.resources.ResourceLoader;
import io.serverlessworkflow.impl.schema.SchemaValidator;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;
Expand All @@ -47,13 +46,13 @@ private WorkflowDefinition(
Input input = workflow.getInput();
this.inputSchemaValidator =
getSchemaValidator(application.validatorFactory(), resourceLoader, input.getSchema());
this.inputFilter = buildWorkflowFilter(application.expressionFactory(), input.getFrom());
this.inputFilter = buildWorkflowFilter(application, input.getFrom());
}
if (workflow.getOutput() != null) {
Output output = workflow.getOutput();
this.outputSchemaValidator =
getSchemaValidator(application.validatorFactory(), resourceLoader, output.getSchema());
this.outputFilter = buildWorkflowFilter(application.expressionFactory(), output.getAs());
this.outputFilter = buildWorkflowFilter(application, output.getAs());
}
this.taskExecutor =
TaskExecutorHelper.createExecutorList(
Expand All @@ -74,7 +73,7 @@ static WorkflowDefinition of(WorkflowApplication application, Workflow workflow,
}

public WorkflowInstance instance(Object input) {
return new WorkflowInstance(this, JsonUtils.fromValue(input));
return new WorkflowInstance(this, application.modelFactory().fromAny(input));
}

Optional<SchemaValidator> inputSchemaValidator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
*/
package io.serverlessworkflow.impl;

import com.fasterxml.jackson.databind.JsonNode;

@FunctionalInterface
public interface WorkflowFilter {
JsonNode apply(WorkflowContext workflow, TaskContext task, JsonNode node);
WorkflowModel apply(WorkflowContext workflow, TaskContext task, WorkflowModel node);
}
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy