Skip to content

Commit

Permalink
GH-1097 Ensure empty POJO converted to {} instead of null
Browse files Browse the repository at this point in the history
Resolves #1097
  • Loading branch information
olegz committed Mar 27, 2024
1 parent cea464a commit 8745f32
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ private JsonMapper jackson(ApplicationContext context) {
}
catch (Exception e) {
mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
}
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
return new JacksonMapper(mapper);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ public void before() {
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
public void testFunctionEligibilityFiltering() {
System.setProperty("spring.cloud.function.ineligible-definitions", "asJsonNode");
Expand Down Expand Up @@ -1433,4 +1442,17 @@ public void setData(V data) {
this.data = data;
}
}
@EnableAutoConfiguration
@Configuration
public static class EmptyPojoConfiguratioin {

@Bean
public Function<String, String> echo() {
return v -> v;
}
}

public static class EmptyPojo {

}
}

0 comments on commit 8745f32

Please sign in to comment.