Skip to content

Commit 8745f32

Browse files
committed
GH-1097 Ensure empty POJO converted to {} instead of null
Resolves #1097
1 parent cea464a commit 8745f32

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/config/ContextFunctionCatalogAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ private JsonMapper jackson(ApplicationContext context) {
219219
}
220220
catch (Exception e) {
221221
mapper = new ObjectMapper();
222-
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
223222
}
223+
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
224224
return new JacksonMapper(mapper);
225225
}
226226
}

spring-cloud-function-context/src/test/java/org/springframework/cloud/function/context/catalog/BeanFactoryAwareFunctionRegistryTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ public void before() {
106106
System.clearProperty("spring.cloud.function.definition");
107107
}
108108

109+
@SuppressWarnings({ "rawtypes", "unchecked" })
110+
@Test
111+
public void testEmptyPojoConversion() {
112+
FunctionCatalog catalog = this.configureCatalog(EmptyPojoConfiguratioin.class);
113+
Function function = catalog.lookup("echo");
114+
String result = (String) function.apply(MessageBuilder.withPayload(new EmptyPojo()).build());
115+
assertThat(result).isEqualTo("{}");
116+
}
117+
109118
@Test
110119
public void testFunctionEligibilityFiltering() {
111120
System.setProperty("spring.cloud.function.ineligible-definitions", "asJsonNode");
@@ -1433,4 +1442,17 @@ public void setData(V data) {
14331442
this.data = data;
14341443
}
14351444
}
1445+
@EnableAutoConfiguration
1446+
@Configuration
1447+
public static class EmptyPojoConfiguratioin {
1448+
1449+
@Bean
1450+
public Function<String, String> echo() {
1451+
return v -> v;
1452+
}
1453+
}
1454+
1455+
public static class EmptyPojo {
1456+
1457+
}
14361458
}

0 commit comments

Comments
 (0)