Using java generics with workflow input

Say I have below workflow

@WorkflowInterface
public interface HelloWorkflow {
    @WorkflowMethod
    <T> int execute(HelloInput<T> input);
}

public class HelloInput<T> {
   List<T> someValue;
   List<T> getValue() {
       return someValue
   }
}

Now Say here T is primitive type then de-serialization works fine, but it contains list of object then it de-serializes them into LinkedHashMap

Wondering if is there any way to generics with workflow input

This is not supported. The invocation of workflows and activities is essentially RPC. Even if we decided to support them, Java makes it practically impossible as there is no runtime information about generic types. And this information is needed for deserialization of the payloads.

ok thanks,
As a workaround wondering if you would recommend using something like JsonNode?
E.g

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;

@WorkflowInterface
public interface HelloWorkflow {
    @WorkflowMethod
    <T> int execute(JsonNode jsonNode, TypeReference<T> typeReference)
}

public interface HelloWorkflowImpl implements HelloWorkflow {

  @Override
   public <T> int execute(JsonNode jsonNode, TypeReference<T> typeReference) {
     final T value = getValue(jsonNode, typeReference);
    // do something 
   }

    public <T> T getValue(JsonNode jsonNode, TypeReference<T> typeReference) {

        try {
            return objectMapper.readValue(
                    jsonNode.toString(), typeReference);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}

Now while calling workflow I can convert pojo to JsonNode
e.g

Class Employee<T> {
  T getValue();
}
JsonNode employeeJsonNode = convert(employee);
execute(employeeJsonNode, new TypeReference<Employee<Finance>>() {})

What is the business problem you are trying to solve? Workflow client and workflow definitions live in different processes. What is the benefit of generics here?

I am trying to create generic batch processing using slidingWindow example here https://github.com/temporalio/samples-java/blob/main/core/src/main/java/io/temporal/samples/batch/slidingwindow/SlidingWindowBatchWorkflowImpl.java

Basically I can use same workflow to do batch processing. And will pass some lambda for RecordProcessorWorkflow which it can execute.

Otherwise I have to write same framework for each of workflow where only processing of single record will be different

@maxim Thoughts?

I"m not sure why you need a lambda here. You can specify a different task queue for each specific RecordProcessingWorklfow implementation.

I can still use same task queue. Basically want different implementation for https://github.com/temporalio/samples-java/blob/main/core/src/main/java/io/temporal/samples/batch/slidingwindow/RecordProcessorWorkflowImpl.java#L49

You either have to use different workflow types or different task queues. Lambdas are not serializable, especially across language barriers.