Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize problem on LocalDate #134

Open
nicktombeur opened this issue May 13, 2023 · 1 comment
Open

Deserialize problem on LocalDate #134

nicktombeur opened this issue May 13, 2023 · 1 comment
Assignees
Labels
bug Something isn't working need investigation Need investigation from a maintainer P3 Priority 3
Milestone

Comments

@nicktombeur
Copy link

When returning an object containing a LocalDate, I get the following error.

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
 at [Source: (String)"{"date":{"year":2023,"month":5,"day":13},"value":"foo"}"; line: 1, column: 1] 
...
 at com.microsoft.durabletask.JacksonDataConverter.deserialize(JacksonDataConverter.java:40)

I believe this date format is coming from protobuf?
I can solve this problem by writing my own custom Jackson deserializer but shouldn't this be handled for us?
Maybe it's possible to return { "date": "2023-05-13" } instead? This way I can add jackson-datatype-jsr310 to the class path and com.microsoft.durabletask.JacksonDataConverter will pick it up.

Example code:

public class ExampleFunction {

    @FunctionName("StartOrchestration")
    public HttpResponseMessage startOrchestration(
            @HttpTrigger(name = "req",
                    methods = {HttpMethod.GET, HttpMethod.POST},
                    authLevel = AuthorizationLevel.ANONYMOUS) final HttpRequestMessage<Optional<String>> request,
            @DurableClientInput(name = "durableContext") final DurableClientContext durableContext,
            final ExecutionContext context) {
        context.getLogger().info("Java HTTP trigger processed a request");

        final DurableTaskClient client = durableContext.getClient();
        final String instanceId = client.scheduleNewOrchestrationInstance("ExampleProcess");
        return durableContext.createCheckStatusResponse(request, instanceId);
    }

    @FunctionName("ExampleProcess")
    public String exampleOrchestrator(
            @DurableOrchestrationTrigger(name = "taskOrchestrationContext") final TaskOrchestrationContext context,
            final ExecutionContext functionContext) {
        return context.callActivity("ToLower", "Foo", String.class).await() +
                    " " +
                    context.callActivity("ToLower", "Bar", String.class).await();
    }

    @FunctionName("ToLower")
    public ExampleResponse toLower(@DurableActivityTrigger(name = "value") final String value, final ExecutionContext context) {
        return new ExampleResponse(LocalDate.now(), value.toLowerCase());
    }
}

public class ExampleResponse {
    private LocalDate date;
    private String value;

   ...
}
@kaibocai kaibocai added Needs: Attention 👋 Needs attention from a maintainer need investigation Need investigation from a maintainer labels May 15, 2023
@kaibocai kaibocai added this to the v1.2.0 milestone May 15, 2023
@kamperiadis kamperiadis self-assigned this Jun 13, 2023
@kaibocai
Copy link
Member

Maybe it's possible to return { "date": "2023-05-13" } instead? This way I can add jackson-datatype-jsr310 to the classpath and com.microsoft.durabletask.JacksonDataConverter will pick it up.

Hi @nicktombeur, thanks for reaching out with this issue. I think there are few reasons that causing this issue for you.

  1. Jackson itself issue with serializing/deserializing java.time.LocalDate. As you pointed out, it could be resolved by adding add jackson-datatype-jsr310 to your classpath and registering the JavaTimeModule. However, we don't expose any interface to customers for example to register modules in ObjectMapper of jackson. So even if you could add add jackson-datatype-jsr310 to your classpath, I don't think there is a way for you to register the module.
  2. the date is serialized as "date":{"year":2023,"month":6,"day":20} instead of { "date": "2023-05-13" }, this is caused by the different formatting between gson used in Azure Function Java Language Worker and jackson used in this repo.

For now please use your own custom Jackson deserializer as a workaround. The team will try to improve this soon. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need investigation Need investigation from a maintainer P3 Priority 3
Projects
None yet
Development

No branches or pull requests

5 participants