microsoft / microsoft/durabletask-java

Deserialize problem on LocalDate

未关闭
#134 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@kamperiadis 已经在做这个了。

开始于 2023年6月13日。

bug need investigation P3
主要语言
Java
星标
29
派生
18
平均合并
1 天 10 小时
30 天内合并 PR
2

描述

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;

   ...
}

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。