|
8 | 8 | // https://github.com/restatedev/sdk-java/blob/main/LICENSE |
9 | 9 | package my.restate.sdk.examples; |
10 | 10 |
|
11 | | -import com.fasterxml.jackson.annotation.JsonCreator; |
12 | | -import com.fasterxml.jackson.annotation.JsonProperty; |
13 | 11 | import dev.restate.sdk.Context; |
14 | 12 | import dev.restate.sdk.JsonSerdes; |
15 | 13 | import dev.restate.sdk.SharedWorkflowContext; |
@@ -45,41 +43,8 @@ public enum Status { |
45 | 43 | TRANSFER_FAILED |
46 | 44 | } |
47 | 45 |
|
48 | | - public static class LoanRequest { |
49 | | - |
50 | | - private final String customerName; |
51 | | - private final String customerId; |
52 | | - private final String customerBankAccount; |
53 | | - private final BigDecimal amount; |
54 | | - |
55 | | - @JsonCreator |
56 | | - public LoanRequest( |
57 | | - @JsonProperty("customerName") String customerName, |
58 | | - @JsonProperty("customerId") String customerId, |
59 | | - @JsonProperty("customerBankAccount") String customerBankAccount, |
60 | | - @JsonProperty("amount") BigDecimal amount) { |
61 | | - this.customerName = customerName; |
62 | | - this.customerId = customerId; |
63 | | - this.customerBankAccount = customerBankAccount; |
64 | | - this.amount = amount; |
65 | | - } |
66 | | - |
67 | | - public String getCustomerName() { |
68 | | - return customerName; |
69 | | - } |
70 | | - |
71 | | - public String getCustomerId() { |
72 | | - return customerId; |
73 | | - } |
74 | | - |
75 | | - public String getCustomerBankAccount() { |
76 | | - return customerBankAccount; |
77 | | - } |
78 | | - |
79 | | - public BigDecimal getAmount() { |
80 | | - return amount; |
81 | | - } |
82 | | - } |
| 46 | + public record LoanRequest( |
| 47 | + String customerName, String customerId, String customerBankAccount, BigDecimal amount) {} |
83 | 48 |
|
84 | 49 | private static final Logger LOG = LogManager.getLogger(LoanWorkflow.class); |
85 | 50 |
|
@@ -123,8 +88,7 @@ public String run(WorkflowContext ctx, LoanRequest loanRequest) { |
123 | 88 | executionTime = |
124 | 89 | bankClient |
125 | 90 | .transfer( |
126 | | - new TransferRequest( |
127 | | - loanRequest.getCustomerBankAccount(), loanRequest.getAmount())) |
| 91 | + new TransferRequest(loanRequest.customerBankAccount(), loanRequest.amount())) |
128 | 92 | .await(Duration.ofDays(7)); |
129 | 93 | } catch (TerminalException | TimeoutException e) { |
130 | 94 | LOG.warn("Transaction failed", e); |
@@ -223,24 +187,5 @@ public Instant transfer(Context context, TransferRequest request) throws Termina |
223 | 187 | } |
224 | 188 | } |
225 | 189 |
|
226 | | - public static class TransferRequest { |
227 | | - private final String bankAccount; |
228 | | - private final BigDecimal amount; |
229 | | - |
230 | | - @JsonCreator |
231 | | - public TransferRequest( |
232 | | - @JsonProperty("bankAccount") String bankAccount, |
233 | | - @JsonProperty("amount") BigDecimal amount) { |
234 | | - this.bankAccount = bankAccount; |
235 | | - this.amount = amount; |
236 | | - } |
237 | | - |
238 | | - public String getBankAccount() { |
239 | | - return bankAccount; |
240 | | - } |
241 | | - |
242 | | - public BigDecimal getAmount() { |
243 | | - return amount; |
244 | | - } |
245 | | - } |
| 190 | + public record TransferRequest(String bankAccount, BigDecimal amount) {} |
246 | 191 | } |
0 commit comments