microsoft / durabletask-java

Java SDK for Durable Functions and the Durable Task Framework
MIT License
13 stars 7 forks source link

com.microsoft.durabletask.DataConverter$DataConverterException in case of no default constructor #78

Closed YusukeTobo closed 1 year ago

YusukeTobo commented 2 years ago

If no default constructor is generated by javac, the following deserializing warning raises in OrchestrationTrigger. The message is not clear for this library users.

WARNING: The orchestrator failed with an unhandled exception: com.microsoft.durabletask.DataConverter$DataConverterException: Failed to deserialize the JSON text to net.yutobo.durablefunc.Person.

Regarding the java debugger output, this warning is from the exception of Jackson.

InvalidDefinitionException@92 "com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `net.yutobo.durablefunc.Person` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: (String)"{"name":"yusuke","age":30}"; line: 1, column: 2]"

Client Function

        Person person = new Person("foobar", 30);
        client.scheduleNewOrchestrationInstance("orchestrateSingleton", person, instanceID);

OrchestrationTrigger

return OrchestrationRunner.loadAndRun(runtimeState, ctx -> {

            Person person = ctx.getInput(Person.class); // com.microsoft.durabletask.DataConverter$DataConverterException
            context.getLogger().info(person.toString());
kaibocai commented 1 year ago

Hi @cgillum , I wonder what should be the fix here. Jackson cannot desterilized model that doesn't have an empty constructor and the model contains constructor with parameters which didn't annotated its parameters with @JsonProperty("field_name").

Should we update the exception message or should we write this restriction on our documents that when cx is using any class defined themselves them need to provide empty constructor?

cgillum commented 1 year ago

@kaibocai I think the first step is to make sure this additional error information is included in the exception we raise.

InvalidDefinitionException@92 "com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of net.yutobo.durablefunc.Person (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (String)"{"name":"yusuke","age":30}"; line: 1, column: 2]"

Then at least developers can understand what happened without needing to use the debugger.