io.nflow.engine.internal.workflow.ObjectStringMapper Maven / Gradle / Ivy
package io.nflow.engine.internal.workflow;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import javax.inject.Inject;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.nflow.engine.config.NFlow;
import io.nflow.engine.internal.workflow.WorkflowStateMethod.StateParameter;
import io.nflow.engine.workflow.definition.Mutable;
import io.nflow.engine.workflow.definition.StateExecution;
@Component
public class ObjectStringMapper {
private final ObjectMapper mapper;
@Inject
public ObjectStringMapper(@NFlow ObjectMapper nflowObjectMapper) {
this.mapper = nflowObjectMapper;
}
@SuppressWarnings("unchecked")
@SuppressFBWarnings(value = "UCC_UNRELATED_COLLECTION_CONTENTS", justification = "args are unrelated")
public Object[] createArguments(StateExecution execution,
WorkflowStateMethod method) {
Object[] args = new Object[method.params.length + 1];
args[0] = execution;
StateParameter[] params = method.params;
for (int i = 1; i <= params.length; i++) {
StateParameter param = params[i - 1];
String value = execution.getVariable(param.key);
if (value == null) {
Object def = param.nullValue;
if (def instanceof Constructor) {
try {
def = ((Constructor