# Using java generics with workflow input

**URL:** <https://community.temporal.io/t/using-java-generics-with-workflow-input/9112>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [August 8, 2023, 6:23pm UTC](https://community.temporal.io/t/using-java-generics-with-workflow-input/9112 "2023-08-08T18:23:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![shivamtiwari2009](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@shivamtiwari2009](https://community.temporal.io/u/shivamtiwari2009)\
**Post date:** [August 8, 2023, 6:23pm UTC](https://community.temporal.io/t/using-java-generics-with-workflow-input/9112/1 "2023-08-08T18:23:04Z")

</div>

Say I have below workflow

```auto
@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

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [August 8, 2023, 6:30pm UTC](https://community.temporal.io/t/using-java-generics-with-workflow-input/9112/2 "2023-08-08T18:30:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shivamtiwari2009](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@shivamtiwari2009](https://community.temporal.io/u/shivamtiwari2009)\
**Post date:** [August 8, 2023, 7:21pm UTC](https://community.temporal.io/t/using-java-generics-with-workflow-input/9112/3 "2023-08-08T19:21:37Z")

</div>

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

```auto
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

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

```

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [August 8, 2023, 8:02pm UTC](https://community.temporal.io/t/using-java-generics-with-workflow-input/9112/4 "2023-08-08T20:02:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![shivamtiwari2009](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@shivamtiwari2009](https://community.temporal.io/u/shivamtiwari2009)\
**Post date:** [August 8, 2023, 8:27pm UTC](https://community.temporal.io/t/using-java-generics-with-workflow-input/9112/5 "2023-08-08T20:27:36Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![shivamtiwari2009](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@shivamtiwari2009](https://community.temporal.io/u/shivamtiwari2009)\
**Post date:** [August 9, 2023, 1:25pm UTC](https://community.temporal.io/t/using-java-generics-with-workflow-input/9112/6 "2023-08-09T13:25:32Z")

</div>

@maxim Thoughts?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [August 9, 2023, 3:10pm UTC](https://community.temporal.io/t/using-java-generics-with-workflow-input/9112/7 "2023-08-09T15:10:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![shivamtiwari2009](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@shivamtiwari2009](https://community.temporal.io/u/shivamtiwari2009)\
**Post date:** [August 9, 2023, 4:13pm UTC](https://community.temporal.io/t/using-java-generics-with-workflow-input/9112/8 "2023-08-09T16:13:18Z")

</div>

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](https://github.com/temporalio/samples-java/blob/main/core/src/main/java/io/temporal/samples/batch/slidingwindow/RecordProcessorWorkflowImpl.java#L49)

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [August 9, 2023, 8:33pm UTC](https://community.temporal.io/t/using-java-generics-with-workflow-input/9112/9 "2023-08-09T20:33:57Z")

</div>

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