Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 532e04b

Browse files
authored
Merge pull request #343 from seongahjo/master
refactor if statement
2 parents 4c7cdba + 0aa8351 commit 532e04b

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

graphql-kickstart-spring-support/src/main/java/graphql/kickstart/spring/AbstractGraphQLController.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.IOException;
1919
import java.util.Collections;
2020
import java.util.Map;
21+
import java.util.Optional;
2122

2223
@RequiredArgsConstructor
2324
public abstract class AbstractGraphQLController {
@@ -34,9 +35,7 @@ public Object graphqlPOST(
3435
@Nullable @RequestBody(required = false) String body,
3536
ServerWebExchange serverWebExchange) throws IOException {
3637

37-
if (body == null) {
38-
body = "";
39-
}
38+
body = Optional.ofNullable(body).orElse("");
4039

4140
// https://graphql.org/learn/serving-over-http/#post-request
4241
//
@@ -107,10 +106,7 @@ public Object graphqlGET(
107106
}
108107

109108
private Map<String, Object> convertVariablesJson(String jsonMap) {
110-
if (jsonMap == null) {
111-
return Collections.emptyMap();
112-
}
113-
return objectMapper.deserializeVariables(jsonMap);
109+
return Optional.ofNullable(jsonMap).map(objectMapper::deserializeVariables).orElseGet(Collections::emptyMap);
114110
}
115111

116112
protected abstract Object executeRequest(

0 commit comments

Comments
 (0)