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 摘要。