Skip to content

Commit 0392add

Browse files
committed
Fix for the empty object serialization issue
For now steps return types will need to be: - Public classes - Having public `JsonProperty`s so that getters can be called from the `inngest-core` package. It's quite limiting I think. Getters do not work as expected with Klaxon unless it's declared in Kotlin. But we'll try to improve it later on.
1 parent 165c193 commit 0392add

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

inngest-spring-boot-demo/src/main/java/com/inngest/springbootdemo/InngestSingleton.java

+7-21
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,6 @@
66
import java.time.Duration;
77
import java.util.HashMap;
88

9-
import com.fasterxml.jackson.annotation.JsonProperty;
10-
11-
// TODO: Fix the serialization yielding an empty object in `Klaxon().toJsonString(body)`
12-
class Result {
13-
@JsonProperty("sum")
14-
private final int sum;
15-
16-
public Result(@JsonProperty("sum") int sum) {
17-
this.sum = sum;
18-
}
19-
20-
public int getSum() {
21-
return sum;
22-
}
23-
}
24-
259
// NOTE: We probably don't need this singleton anymore
2610
// when revisiting the SDK's interface.
2711
public class InngestSingleton {
@@ -33,7 +17,7 @@ public static synchronized CommHandler getInstance() {
3317
FunctionTrigger[] triggers = {fnTrigger};
3418
FunctionOptions fnConfig = new FunctionOptions("fn-id-slug", "My function!", triggers);
3519

36-
Function2<FunctionContext, Step, Void> handler = (ctx, step) -> {
20+
Function2<FunctionContext, Step, HashMap<String, String>> handler = (ctx, step) -> {
3721
int x = 10;
3822

3923
System.out.println("-> handler called " + ctx.getEvent().getName());
@@ -47,15 +31,17 @@ public static synchronized CommHandler getInstance() {
4731

4832
System.out.println("res" + res);
4933
int add = step.run("add-one-hundred", () -> {
50-
System.out.println("-> running step 2 :) " + (res != null ? res.getSum() : ""));
51-
return (res != null ? res.getSum() : 0) + 100;
34+
System.out.println("-> running step 2 :) " + (res != null ? res.sum : ""));
35+
return (res != null ? res.sum : 0) + 100;
5236
}, Integer.class);
5337

5438
step.sleep("wait-one-sec", Duration.ofSeconds(2));
5539

56-
step.run("last-step", () -> (res != null ? res.getSum() : 0) * add, Integer.class);
40+
step.run("last-step", () -> (res != null ? res.sum : 0) * add, Integer.class);
5741

58-
return null;
42+
return new HashMap<String, String>() {{
43+
put("message", "cool - this finished running");
44+
}};
5945
};
6046
InngestFunction function = new InngestFunction(fnConfig, handler);
6147

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.inngest.springbootdemo;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
public class Result {
6+
@JsonProperty("sum")
7+
public final int sum;
8+
9+
public Result(@JsonProperty("sum") int sum) {
10+
this.sum = sum;
11+
}
12+
}

0 commit comments

Comments
 (0)