-
Couldn't load subscription status.
- Fork 38.8k
Closed as not planned
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply
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());
}
}Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply