GH-1097 Ensure empty POJO converted to {} instead of null
Resolves #1097
This commit is contained in:
@@ -219,8 +219,8 @@ public class ContextFunctionCatalogAutoConfiguration {
|
|||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
|
||||||
}
|
}
|
||||||
|
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||||
return new JacksonMapper(mapper);
|
return new JacksonMapper(mapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,15 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
|||||||
System.clearProperty("spring.cloud.function.definition");
|
System.clearProperty("spring.cloud.function.definition");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
@Test
|
||||||
|
public void testEmptyPojoConversion() {
|
||||||
|
FunctionCatalog catalog = this.configureCatalog(EmptyPojoConfiguratioin.class);
|
||||||
|
Function function = catalog.lookup("echo");
|
||||||
|
String result = (String) function.apply(MessageBuilder.withPayload(new EmptyPojo()).build());
|
||||||
|
assertThat(result).isEqualTo("{}");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFunctionEligibilityFiltering() {
|
public void testFunctionEligibilityFiltering() {
|
||||||
System.setProperty("spring.cloud.function.ineligible-definitions", "asJsonNode");
|
System.setProperty("spring.cloud.function.ineligible-definitions", "asJsonNode");
|
||||||
@@ -1433,4 +1442,17 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
|||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@Configuration
|
||||||
|
public static class EmptyPojoConfiguratioin {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Function<String, String> echo() {
|
||||||
|
return v -> v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EmptyPojo {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user