# How to define Workflow method arguments and return values as Java interface or abstract class?

**URL:** <https://community.temporal.io/t/how-to-define-workflow-method-arguments-and-return-values-as-java-interface-or-abstract-class/944>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [November 10, 2020, 5:33pm UTC](https://community.temporal.io/t/how-to-define-workflow-method-arguments-and-return-values-as-java-interface-or-abstract-class/944 "2020-11-10T17:33:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://community.temporal.io/u/patrick)\
**Post date:** [November 10, 2020, 5:33pm UTC](https://community.temporal.io/t/how-to-define-workflow-method-arguments-and-return-values-as-java-interface-or-abstract-class/944/1 "2020-11-10T17:33:39Z")

</div>

I want to define Workflow method arguments and return values as Java interface so the API is generic (without using Java generic since I don’t know all implementations of the interface). Is this supported OOTB?

I understand the default JSON data converter doesn’t know how to de/serialize interface/abstract classes. Is the only way is to provide my own data converter? If yes, then it’s not “elegant” since I can only provide data converter once per Temporal workflow client which my app has only one, therefore, I have to “inspect” the payload type, i.e., having conditional which I don’t want to do and I don’t want one workflow client per workflow type.

---

<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:** [November 11, 2020, 5:33pm UTC](https://community.temporal.io/t/how-to-define-workflow-method-arguments-and-return-values-as-java-interface-or-abstract-class/944/4 "2020-11-11T17:33:42Z")

</div>

By default Temporal uses Jackson for serialization and deserialization of arguments. It looks like Jackson [supports polymorphic deserialization](https://github.com/FasterXML/jackson-docs/wiki/JacksonPolymorphicDeserialization). It needs to be configured, but DataConverter APIs allow such configuration.

I personally would not recommend going this route as RPC that passes around non value classes is too brittle for my taste.

---

<div class="post-metadata">

**Author:** ![Tucker\_Barbour](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tucker_barbour/32/136_2.png) [@Tucker\_Barbour](https://community.temporal.io/u/Tucker_Barbour)\
**Post date:** [November 16, 2020, 8:50pm UTC](https://community.temporal.io/t/how-to-define-workflow-method-arguments-and-return-values-as-java-interface-or-abstract-class/944/5 "2020-11-16T20:50:05Z")

</div>

I’ve successfully used Jackson’s polymorphic deserialisation without having to define a custom data converter. Just using the `@JsonTypeInfo` and `JsonSubTypes` annotations on my value objects. I can then define both Workflow methods and Activity methods to accept and return Interface types rather than concrete classes. Here is an example in Kotlin. I _think_ there are other ways to define the subtypes with Jackson annotations but this is the way that I knew how to do with Jackson.

```auto
@JsonTypeInfo(
  use = Id.NAME,
  include = As.Property,
  property = "@type"
)
@JsonSubTypes(
  JsonSubTypes.Type(value = First::class, name = "first"),
  JsonSubTypes.Type(value = Second::class, name = "second")
)
interface CustomInterface

data class First(
  @JsonProperty val first: String
) : CustomInterface

data class Second(
  @JsonProperty val second: Long
) : CustomInterface

```

The JSON payloads you’ll get for these will look like

```json
{
  "@type": "first",
  "first": "this is a value"
}

{
  "@type": "second",
  "second": 123456789
}

```

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://community.temporal.io/u/patrick)\
**Post date:** [November 16, 2020, 9:20pm UTC](https://community.temporal.io/t/how-to-define-workflow-method-arguments-and-return-values-as-java-interface-or-abstract-class/944/6 "2020-11-16T21:20:12Z")

</div>

Thanks Tucker. Let me explore this approach.
