Skip to content

Commit 9a91a05

Browse files
committed
Revert "[Fix #380] oneOf as Optional"
This reverts commit eb0b906.
1 parent eb0b906 commit 9a91a05

File tree

7 files changed

+11
-40
lines changed

7 files changed

+11
-40
lines changed

api/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
<groupId>com.fasterxml.jackson.dataformat</groupId>
3030
<artifactId>jackson-dataformat-yaml</artifactId>
3131
</dependency>
32-
<dependency>
33-
<groupId>com.fasterxml.jackson.datatype</groupId>
34-
<artifactId>jackson-datatype-jdk8</artifactId>
35-
</dependency>
3632
<dependency>
3733
<groupId>jakarta.validation</groupId>
3834
<artifactId>jakarta.validation-api</artifactId>

api/src/main/java/io/serverlessworkflow/api/ObjectMapperFactory.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.fasterxml.jackson.databind.module.SimpleModule;
2121
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
2222
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
23-
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
2423
import io.serverlessworkflow.api.types.CallTask;
2524
import io.serverlessworkflow.api.types.SwitchItem;
2625
import io.serverlessworkflow.api.types.Task;
@@ -56,8 +55,7 @@ private static ObjectMapper configure(ObjectMapper mapper) {
5655
.configure(SerializationFeature.INDENT_OUTPUT, true)
5756
.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false)
5857
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false)
59-
.registerModule(simpleModule)
60-
.registerModule(new Jdk8Module());
58+
.registerModule(simpleModule);
6159
}
6260

6361
private ObjectMapperFactory() {}

api/src/main/java/io/serverlessworkflow/api/SerializeHelper.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
import com.fasterxml.jackson.core.JsonGenerator;
1919
import java.io.IOException;
2020
import java.lang.reflect.Method;
21-
import java.util.Optional;
2221

2322
public class SerializeHelper {
2423
public static void serializeOneOf(JsonGenerator jgen, Object item) throws IOException {
2524
try {
2625
for (Method m : item.getClass().getDeclaredMethods()) {
27-
Optional<?> value = (Optional<?>) m.invoke(item);
28-
if (value.isPresent()) {
26+
Object value = m.invoke(item);
27+
if (value != null) {
2928
jgen.writeObject(value);
3029
break;
3130
}

api/src/test/java/io/serverlessworkflow/api/ApiTest.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import io.serverlessworkflow.api.types.Task;
2424
import io.serverlessworkflow.api.types.Workflow;
2525
import java.io.IOException;
26-
import java.util.Optional;
2726
import org.junit.jupiter.api.Test;
2827

2928
public class ApiTest {
@@ -35,12 +34,12 @@ void testCallHTTPAPI() throws IOException {
3534
assertThat(workflow.getDo().get(0).getName()).isNotNull();
3635
assertThat(workflow.getDo().get(0).getTask()).isNotNull();
3736
Task task = workflow.getDo().get(0).getTask();
38-
Optional<CallTask> callTask = task.getCallTask();
39-
assertThat(callTask).isPresent();
40-
assertThat(task.getDoTask()).isEmpty();
41-
Optional<CallHTTP> httpCall = callTask.flatMap(CallTask::getCallHTTP);
42-
assertThat(httpCall).isPresent();
43-
assertThat(callTask.flatMap(CallTask::getCallAsyncAPI)).isEmpty();
44-
assertThat(httpCall.get().getWith().getMethod()).isEqualTo("get");
37+
CallTask callTask = task.getCallTask();
38+
assertThat(callTask).isNotNull();
39+
assertThat(task.getDoTask()).isNull();
40+
CallHTTP httpCall = callTask.getCallHTTP();
41+
assertThat(httpCall).isNotNull();
42+
assertThat(callTask.getCallAsyncAPI()).isNull();
43+
assertThat(httpCall.getWith().getMethod()).isEqualTo("get");
4544
}
4645
}

custom-generator/src/main/java/io/serverlessworkflow/generator/AllAnyOneOfSchemaRule.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private JDefinedClass createUnionClass(
125125

126126
private void wrapIt(JDefinedClass definedClass, JType unionType) {
127127
JFieldVar instanceField =
128-
GeneratorUtils.addOptionalGetter(
128+
GeneratorUtils.addGetter(
129129
definedClass, unionType, ruleFactory.getNameHelper(), unionType.name());
130130
JMethod constructor = definedClass.constructor(JMod.PUBLIC);
131131
constructor

custom-generator/src/main/java/io/serverlessworkflow/generator/GeneratorUtils.java

-16
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
*/
1616
package io.serverlessworkflow.generator;
1717

18-
import com.sun.codemodel.JClass;
1918
import com.sun.codemodel.JDefinedClass;
2019
import com.sun.codemodel.JFieldVar;
2120
import com.sun.codemodel.JMethod;
2221
import com.sun.codemodel.JMod;
2322
import com.sun.codemodel.JType;
24-
import java.util.Optional;
2523
import org.jsonschema2pojo.util.NameHelper;
2624

2725
public class GeneratorUtils {
@@ -36,19 +34,5 @@ public static JFieldVar addGetter(
3634
return instanceField;
3735
}
3836

39-
public static JFieldVar addOptionalGetter(
40-
JDefinedClass definedClass, JType type, NameHelper nameHelper, String name) {
41-
JFieldVar instanceField =
42-
definedClass.field(JMod.PRIVATE, type, nameHelper.getPropertyName(name, null));
43-
JClass optionalRef = definedClass.owner().ref(Optional.class).narrow(type);
44-
JMethod method =
45-
definedClass.method(JMod.PUBLIC, optionalRef, nameHelper.getGetterName(name, type, null));
46-
method
47-
.body()
48-
._return(
49-
definedClass.owner().ref(Optional.class).staticInvoke("ofNullable").arg(instanceField));
50-
return instanceField;
51-
}
52-
5337
private GeneratorUtils() {}
5438
}

pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@
114114
<artifactId>jackson-core</artifactId>
115115
<version>${version.com.fasterxml.jackson}</version>
116116
</dependency>
117-
<dependency>
118-
<groupId>com.fasterxml.jackson.datatype</groupId>
119-
<artifactId>jackson-datatype-jdk8</artifactId>
120-
<version>${version.com.fasterxml.jackson}</version>
121-
</dependency>
122117
<dependency>
123118
<groupId>com.fasterxml.jackson.core</groupId>
124119
<artifactId>jackson-databind</artifactId>

0 commit comments

Comments
 (0)