Skip to content

Commit

Permalink
GH-1117 Enhance support for function composition to handle null returns
Browse files Browse the repository at this point in the history
Resolves #1117
  • Loading branch information
olegz committed Mar 27, 2024
1 parent 8745f32 commit d70079e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ Object doApply(Object input) {

input = this.fluxifyInputIfNecessary(input);

Object convertedInput = this.convertInputIfNecessary(input, this.inputType);
Object convertedInput = input == null ? null : this.convertInputIfNecessary(input, this.inputType);

if (this.isRoutingFunction() || this.isComposed()) {
result = ((Function) this.target).apply(convertedInput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ public void testEmptyPojoConversion() {
assertThat(result).isEqualTo("{}");
}

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testCompositionWithNullReturnInBetween() {
FunctionCatalog catalog = this.configureCatalog(CompositionWithNullReturnInBetween.class);
Function function = catalog.lookup("echo1|echo2");
String result = (String) function.apply(MessageBuilder.withPayload(new EmptyPojo()).build());
assertThat(result).isEqualTo("null");
}

@Test
public void testFunctionEligibilityFiltering() {
System.setProperty("spring.cloud.function.ineligible-definitions", "asJsonNode");
Expand Down Expand Up @@ -1455,4 +1464,24 @@ public Function<String, String> echo() {
public static class EmptyPojo {

}

@EnableAutoConfiguration
@Configuration
public static class CompositionWithNullReturnInBetween {

@Bean
public Function<String, String> echo1() {
return v -> null;
}
@Bean
public Function<String, String> echo2() {
return v -> {
if (v == null) {
return "null";
}
return v;
};
}
}

}

0 comments on commit d70079e

Please sign in to comment.