Skip to content

Commit 25387be

Browse files
Add default methods for exceptionToFailure and failureToException (#1809)
Add default methods for exceptionToFailure and failureToException
1 parent 15337d9 commit 25387be

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

temporal-sdk/src/main/java/io/temporal/common/converter/DataConverter.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222

2323
import com.fasterxml.jackson.databind.ObjectMapper;
2424
import com.google.common.base.Defaults;
25+
import com.google.common.base.Preconditions;
2526
import io.temporal.api.common.v1.Payload;
2627
import io.temporal.api.common.v1.Payloads;
2728
import io.temporal.api.failure.v1.Failure;
2829
import io.temporal.common.Experimental;
30+
import io.temporal.failure.DefaultFailureConverter;
2931
import io.temporal.failure.TemporalFailure;
3032
import io.temporal.payload.codec.PayloadCodec;
3133
import io.temporal.payload.context.SerializationContext;
@@ -174,7 +176,10 @@ default Object[] fromPayloads(
174176
* @throws NullPointerException if failure is null
175177
*/
176178
@Nonnull
177-
TemporalFailure failureToException(@Nonnull Failure failure);
179+
default TemporalFailure failureToException(@Nonnull Failure failure) {
180+
Preconditions.checkNotNull(failure, "failure");
181+
return new DefaultFailureConverter().failureToException(failure, this);
182+
}
178183

179184
/**
180185
* Serialize an existing Throwable object into a Failure object. The default implementation
@@ -185,7 +190,10 @@ default Object[] fromPayloads(
185190
* @throws NullPointerException if throwable is null
186191
*/
187192
@Nonnull
188-
Failure exceptionToFailure(@Nonnull Throwable throwable);
193+
default Failure exceptionToFailure(@Nonnull Throwable throwable) {
194+
Preconditions.checkNotNull(throwable, "throwable");
195+
return new DefaultFailureConverter().exceptionToFailure(throwable, this);
196+
}
189197

190198
/**
191199
* A correct implementation of this interface should have a fully functional "contextless"

0 commit comments

Comments
 (0)