How to return JSONObject from Activity to Workflow

I’m getting this exception

Caused by: io.temporal.common.converter.DataConverterException: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "empty" (class org.json.JSONObject), not marked as ignorable (one known property: "map"])

I tried to use https://github.com/FasterXML/jackson-datatypes-misc but did not work. Is it because the sdk is using a mapper that I cannot modify to support JSONObject?

I switched to use JsonNode from fasterxml.jackson
I suggest change have Temporal’s jackson mapper support org.json. It’s probably a one line change. I feel over time org.json will be very popular
But of course once Temporal support Typescript I’m out of Java

I’m confused. Are you trying to return JSONObject instead of its serialized form from an activity? Have you considered returning byte array that contains the serialized JSON?

Yes. I was returning JSONObject directly from Activity. Jackson automatically tries to serialize it but failed. I then switched to return JsonNode instead

I see. I don’t think we can change the default from Jackson, as it can be a breaking change. The good news that DataConverter is fully pluggable and you can choose whatever serializer you prefer.

Could you provide more info on DataConverter
I found only 2 mentions in the doc https://docs.temporal.io/search?q=DataConverter

We are planning to fully rewrite the SDKs documentation. DataConverter will be also covered.