diff --git a/sdk/src/main/java/io/dapr/client/domain/FailurePolicy.java b/sdk/src/main/java/io/dapr/client/domain/FailurePolicy.java index 8185bfe73e..25eaf03ae1 100644 --- a/sdk/src/main/java/io/dapr/client/domain/FailurePolicy.java +++ b/sdk/src/main/java/io/dapr/client/domain/FailurePolicy.java @@ -19,7 +19,7 @@ /** * Set a failure policy for the job or reminder. */ -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "failurePolicyType", include = JsonTypeInfo.As.EXISTING_PROPERTY) @JsonSubTypes({ @JsonSubTypes.Type(value = DropFailurePolicy.class, name = "DROP"), @JsonSubTypes.Type(value = ConstantFailurePolicy.class, name = "CONSTANT") diff --git a/sdk/src/test/java/io/dapr/serializer/FailurePolicySerializerTest.java b/sdk/src/test/java/io/dapr/serializer/FailurePolicySerializerTest.java new file mode 100644 index 0000000000..67b999aab9 --- /dev/null +++ b/sdk/src/test/java/io/dapr/serializer/FailurePolicySerializerTest.java @@ -0,0 +1,58 @@ +/* + * Copyright 2026 The Dapr Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and +limitations under the License. +*/ + +package io.dapr.serializer; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import io.dapr.client.domain.ConstantFailurePolicy; +import io.dapr.client.domain.DropFailurePolicy; +import org.junit.jupiter.api.Test; + +import java.time.Duration; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class FailurePolicySerializerTest { + + @Test + public void constantPolicyTest() + throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + + var p = new ConstantFailurePolicy(); + p.setMaxRetries(3); + p.setDurationBetweenRetries(Duration.ofSeconds(0)); + var json = mapper.writeValueAsString(p); + + assertEquals( + "{\"maxRetries\":3,\"durationBetweenRetries\":0.0,\"failurePolicyType\":\"CONSTANT\"}", + json); + } + + @Test + public void dropPolicyTest() + throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + + var p = new DropFailurePolicy(); + var json = mapper.writeValueAsString(p); + + assertEquals( + "{\"failurePolicyType\":\"DROP\"}", + json); + } +}