I’ve found a problem with the class ApplicationFailure (Java SDK 1.0.4).
Background for context: within an activity, to return an exception and indicate as retryable or non-retryable, you use ApplicationFailure#newFailure(..) or ApplicationFailure#newNonRetryableFailure. Within the workflow, this is wrapped by an ActivityFailure exception, of which the cause is the ApplicationFailure.
This works, because the SDK converts the exception into a Failure (for return to the server) with FailureConverter.exceptionToFailure(..).
Now imagine we’re using activity with doNotCompleteOnReturn(). You complete the activity with a call to an instance of ActivityCompletionClient. It doesn’t seem wise to make calls to ActivityCompletionClient within the workflow, therefore, you have to call from an activity (preferable a local one, briefly considered sideEffect(..) but I don’t think that’s applicable here). To call the activity, you call from a workflow. However, if you pass an instance of ApplicationFailure into the activity – Jackson can’t serialize it. You get:
io.temporal.common.converter.DataConverterException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.google.protobuf.UnknownFieldSet$Parser and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: io.temporal.failure.ApplicationFailure["failure"]->java.util.Optional["value"]->io.temporal.api.failure.v1.Failure["unknownFields"]->com.google.protobuf.UnknownFieldSet["parserForType"])
The issue is the field TemporalFailure#failure: Jackson doesn’t know how to serialize it. The failure appears to be a convenience when building the message to send back to Temporal.
I did try creating a new ApplicationFailure, but it cannot serialize an empty failure value with.
The only solution I can see, is not passing the exception at all, but manually passing message and type values into an activity, building the ApplicationFailure there, then sending it ActivityCompletionClient.
Can we consider a changing ApplicationFailure, such that it can be serialized with Jackson? This might be as simple as flagging the failure field as Jackson/ignore.
Many thanks!
Sean

