Add ParameterNamesModule to "well known" jackson modules

See gh-27511
This commit is contained in:
Sam Kruglov
2021-10-02 20:50:59 +03:00
committed by Sébastien Deleuze
parent f054c2e804
commit 2f43f77dd1
3 changed files with 35 additions and 0 deletions

View File

@@ -85,6 +85,8 @@ import org.springframework.http.ProblemDetail;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
@@ -255,6 +257,25 @@ class Jackson2ObjectMapperBuilderTests {
assertThat(serializers.findSerializer(null, SimpleType.construct(Integer.class), null).getClass()).isSameAs(CustomIntegerSerializer.class);
}
static class ParameterModuleDto {
int x;
int y;
ParameterModuleDto(int x, int y) {
this.x = x;
this.y = y;
}
int getX() {
return x;
}
int getY() {
return y;
}
}
@Test
void wellKnownModules() throws JsonProcessingException, UnsupportedEncodingException {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
@@ -265,6 +286,9 @@ class Jackson2ObjectMapperBuilderTests {
Optional<String> optional = Optional.of("test");
assertThat(new String(objectMapper.writeValueAsBytes(optional), "UTF-8")).isEqualTo("\"test\"");
assertThatCode(() -> objectMapper.readValue("{\"x\":1,\"y\":2}", ParameterModuleDto.class)).doesNotThrowAnyException();
// Kotlin module
IntRange range = new IntRange(1, 3);
assertThat(new String(objectMapper.writeValueAsBytes(range), "UTF-8")).isEqualTo("{\"start\":1,\"end\":3}");