# Customize serialization / deserialization of java pojo

**URL:** <https://community.temporal.io/t/customize-serialization-deserialization-of-java-pojo/3034>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [September 26, 2021, 8:26pm UTC](https://community.temporal.io/t/customize-serialization-deserialization-of-java-pojo/3034 "2021-09-26T20:26:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![darewreck](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@darewreck](https://community.temporal.io/u/darewreck)\
**Post date:** [September 26, 2021, 8:26pm UTC](https://community.temporal.io/t/customize-serialization-deserialization-of-java-pojo/3034/1 "2021-09-26T20:26:43Z")

</div>

Hi,

I was wondering if there is an example of how to create and register a custom serializer for the DataConverter for a specific data type. Ex. I have a data type that has defined interfaces within it, so the default deserializer/serializer won’t be able to determine what type the interfaces really are so I need to use a couple custom adapter registered to gson for example. So what im looking for is to specify that for this type, use this serailizer/deserializer for the DataCoverter.

I saw a post referencing [sdk-java/PayloadConverter.java at master · temporalio/sdk-java · GitHub](https://github.com/temporalio/sdk-java/blob/master/temporal-sdk/src/main/java/io/temporal/common/converter/PayloadConverter.java) and this [sdk-java/DefaultDataConverter.java at 45de2dc97486f38b57d5320eb9fdd04e098bd6f0 · temporalio/sdk-java · GitHub](https://github.com/temporalio/sdk-java/blob/45de2dc97486f38b57d5320eb9fdd04e098bd6f0/temporal-sdk/src/main/java/io/temporal/common/converter/DefaultDataConverter.java#L97), but its not clear how the specific type is registered to a specific converter payload.

Thanks,  
Derek

---

<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:** [September 26, 2021, 8:31pm UTC](https://community.temporal.io/t/customize-serialization-deserialization-of-java-pojo/3034/2 "2021-09-26T20:31:11Z")

</div>

The default DataConverter uses [JacksonJsonPayloadConverter](https://github.com/temporalio/sdk-java/blob/master/temporal-sdk/src/main/java/io/temporal/common/converter/JacksonJsonPayloadConverter.java) to serialize Java types. Please consult the [Jackson documentation](https://github.com/FasterXML/jackson) on how to annotate your classes to support polymorphic types.

Here is [one of the possible answers](https://stackoverflow.com/questions/34136471/polymorphic-serialization-using-jackson-when-return-type-is-marker-interface) from the stackoverflow.

---

<div class="post-metadata">

**Author:** ![darewreck](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@darewreck](https://community.temporal.io/u/darewreck)\
**Post date:** [September 27, 2021, 4:03am UTC](https://community.temporal.io/t/customize-serialization-deserialization-of-java-pojo/3034/3 "2021-09-27T04:03:39Z")

</div>

The problem is that the data types are from a third party library that I don’t control so Im not able to modify or annotate the classes…

---

<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:** [September 27, 2021, 3:49pm UTC](https://community.temporal.io/t/customize-serialization-deserialization-of-java-pojo/3034/4 "2021-09-27T15:49:21Z")

</div>

Then you can configure Jackson object mapper configuration itself. Something like:

```java
    ObjectMapper objectMapper =
        new ObjectMapper()
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true)
            .registerModule(new JavaTimeModule());
    DataConverter converter =
        DefaultDataConverter.getDefaultInstance()
            .withPayloadConverterOverrides(new JacksonJsonPayloadConverter(objectMapper));

```
