Closed as not planned
Description
As mentioned here: #27697 (comment)
Since migrating from Spring Boot 2.7.x to 3.3.x the jackson ObjectMapper is not able to serialize org.springframework.http.HttpMethod
anymore. You have to write now your own modules with serializer and deserializer now.
public class JacksonConfig{
@Bean
SimpleModule httpMethodModule() {
SimpleModule module = new SimpleModule();
module.addSerializer(HttpMethod.class, new HttpMethodSerializer());
module.addDeserializer(HttpMethod.class, new HttpMethodDeserializer());
return module;
}
@Bean
Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
return builder -> builder
.modules(httpMethodModule());
}
}
public class HttpMethodSerializer extends JsonSerializer<HttpMethod> {
@Override
public void serialize(HttpMethod httpMethod, JsonGenerator jsonGenerator, SerializerProvider serializers) throws IOException {
jsonGenerator.writeString(httpMethod.name());
}
}
public class HttpMethodDeserializer extends JsonDeserializer<HttpMethod> {
@Override
public HttpMethod deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
return HttpMethod.valueOf(jsonParser.getText().toUpperCase());
}
}