Title: Customizable Serialization for Activity Return Values in Durable Functions · Issue #206 · microsoft/durabletask-java · GitHub
Open Graph Title: Customizable Serialization for Activity Return Values in Durable Functions · Issue #206 · microsoft/durabletask-java
X Title: Customizable Serialization for Activity Return Values in Durable Functions · Issue #206 · microsoft/durabletask-java
Description: What’s the problem? Hey👋, I'm working with Durable Functions in Java, and I’ve encountered an issue with how activity return values are serialized. Specifically: Activity functions return POJOs annotated with Jackson and Gson and having ...
Open Graph Description: What’s the problem? Hey👋, I'm working with Durable Functions in Java, and I’ve encountered an issue with how activity return values are serialized. Specifically: Activity functions return POJOs ann...
X Description: What’s the problem? Hey👋, I'm working with Durable Functions in Java, and I’ve encountered an issue with how activity return values are serialized. Specifically: Activity functions return POJOs...
Opengraph URL: https://github.com/microsoft/durabletask-java/issues/206
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Customizable Serialization for Activity Return Values in Durable Functions","articleBody":"## **What’s the problem?**\nHey👋, \n\nI'm working with **Durable Functions in Java**, and I’ve encountered an issue with how **activity return values are serialized**. Specifically: \n\n- **Activity functions return POJOs** annotated with Jackson and Gson and having subTypes, which is deserialized using Gson when entering the activity but none is used for serializing return value. \n- This creates **inconsistencies**. \n- There's **no way to customize** the serialization mechanism for Durable Functions activities. \n- Raises an Exception of InvalidTypeIdException because the type is missing at com.microsoft.durabletask.JacksonDataConverter#deserialize. \n\n---\n\n## **How to reproduce it?**\nHere’s a minimal Durable Function example where an **Activity returns a POJO**, but the **Azure Functions Java Worker does not deserialize it properly**:\n\n### **1️⃣ POJO with Jackson & Gson annotations and Subtypes**\n```java\nimport com.fasterxml.jackson.annotation.JsonSubTypes;\nimport com.fasterxml.jackson.annotation.JsonTypeInfo;\nimport com.fasterxml.jackson.annotation.JsonProperty;\nimport com.google.gson.annotations.JsonAdapter;\nimport com.google.gson.annotations.SerializedName;\nimport com.google.gson.*;\nimport java.io.IOException;\n\n@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = \"type\")\n@JsonSubTypes({\n @JsonSubTypes.Type(value = AdminUser.class, name = \"admin\"),\n @JsonSubTypes.Type(value = RegularUser.class, name = \"regular\")\n})\n@JsonAdapter(UserTypeAdapter.class)\npublic abstract class User {\n private String id;\n\n private String name;\n\n public User() {}\n\n public User(String id, String name) {\n this.id = id;\n this.name = name;\n }\n\n public String getId() { return id; }\n public String getName() { return name; }\n}\n\npublic class AdminUser extends User {\n private int adminLevel;\n\n public AdminUser() {}\n public AdminUser(String id, String name, int adminLevel) {\n super(id, name);\n this.adminLevel = adminLevel;\n }\n}\n\npublic class RegularUser extends User {\n private String membershipStatus;\n\n public RegularUser() {}\n public RegularUser(String id, String name, String membershipStatus) {\n super(id, name);\n this.membershipStatus = membershipStatus;\n }\n}\n\npublic class UserTypeAdapter extends TypeAdapter\u003cUser> {\n @Override\n public void write(JsonWriter out, User user) throws IOException {\n out.beginObject();\n out.name(\"type\").value(user instanceof AdminUser ? \"admin\" : \"regular\");\n out.name(\"id\").value(user.getId());\n out.name(\"name\").value(user.getName());\n if (user instanceof AdminUser) {\n out.name(\"adminLevel\").value(((AdminUser) user).adminLevel);\n } else if (user instanceof RegularUser) {\n out.name(\"membershipStatus\").value(((RegularUser) user).membershipStatus);\n }\n out.endObject();\n }\n\n @Override\n public User read(JsonReader in) throws IOException {\n in.beginObject();\n String type = \"\";\n String id = \"\";\n String name = \"\";\n int adminLevel = 0;\n String membershipStatus = \"\";\n \n while (in.hasNext()) {\n String fieldName = in.nextName();\n switch (fieldName) {\n case \"type\":\n type = in.nextString();\n break;\n case \"id\":\n id = in.nextString();\n break;\n case \"name\":\n name = in.nextString();\n break;\n case \"adminLevel\":\n adminLevel = in.nextInt();\n break;\n case \"membershipStatus\":\n membershipStatus = in.nextString();\n break;\n default:\n in.skipValue();\n break;\n }\n }\n in.endObject();\n \n return \"admin\".equals(type) ? new AdminUser(id, name, adminLevel) : new RegularUser(id, name, membershipStatus);\n }\n}\n```\n\n## **What do you want to happen?**\n✅ **Supporting GSON for serialization**. \n\n","author":{"url":"https://github.com/MANDA-LAWINE","@type":"Person","name":"MANDA-LAWINE"},"datePublished":"2025-03-16T19:01:07Z","url":"https://github.com/microsoft/durabletask-java/issues/206"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7c7648ee-5052-379a-c655-9becace85e7e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AAA2:1A9D43:83A69:AC6B8:6AFE31C7 |
| html-safe-nonce | df8b816bf091210d0f88d89d758bd20e4d64a6d296704a9bc8ababf6e8599f17 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQUEyOjFBOUQ0Mzo4M0E2OTpBQzZCODo2QUZFMzFDNyIsInZpc2l0b3JfaWQiOiIxNDQxODIwNTQ4ODMyMDQ3NTU5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 99860d6f6b88513daf40405e8c7a68f1df301bafd02fa25e92ce9a4b59237107 |
| hovercard-subject-tag | issue:2923249004 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/durabletask-java/206/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3ed4e52067e089f21db78d672c3674f46f4863dc11213a528f22bf359e962b56/microsoft/durabletask-java/issues/206 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3ed4e52067e089f21db78d672c3674f46f4863dc11213a528f22bf359e962b56/microsoft/durabletask-java/issues/206 |
| og:image:alt | What’s the problem? Hey👋, I'm working with Durable Functions in Java, and I’ve encountered an issue with how activity return values are serialized. Specifically: Activity functions return POJOs ann... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | MANDA-LAWINE |
| hostname | github.com |
| expected-hostname | github.com |
| None | d70e31220a67f6376c108d2416fa8e7df854c1065b1672ab7a88ab6dc3a809e2 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/durabletask-java git https://github.com/microsoft/durabletask-java.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 452823832 |
| octolytics-dimension-repository_nwo | microsoft/durabletask-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 452823832 |
| octolytics-dimension-repository_network_root_nwo | microsoft/durabletask-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ccb88d9c92abe69245b429398c8a57ae87070c7c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width