Jackson2ObjectMapperBuilderCustomizer does not support Jackson JsonReadFeature, JsonWriteFeature, StreamWriteFeature #31230
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
Uh oh!
There was an error while loading. Please reload this page.
Description
When customizing Jackson's ObjectMapper via
Jackson2ObjectMapperBuilderCustomizer
in Spring Boot, attempting to configureJsonReadFeatures
like below causesIllegalArgumentException
:This is because Jackson2ObjectMapperBuilder currently only supports configuring a limited set of feature types including JsonParser.Feature, JsonGenerator.Feature, SerializationFeature, DeserializationFeature and MapperFeature.
But JsonReadFeature, JsonWriteFeature, StreamWriteFeature introduced in Jackson 2.10 is not supported yet. So enabling it via customize() method throws exception:
IllegalArgumentException: Unknown feature class: com.fasterxml.jackson.core.json.JsonReadFeature
IllegalArgumentException: Unknown feature class: com.fasterxml.jackson.core.json.JsonWriteFeature
IllegalArgumentException: Unknown feature class: com.fasterxml.jackson.core.json.StreamWriteFeature
Root Cause
The root cause is org.springframework.http.converter.json.Jackson2ObjectMapperBuilder#configureFeature() method hardcoded checking for those feature types but not handling JsonReadFeature, JsonWriteFeature, JsonWriteFeature.
Versions
This issue occurs on latest Spring Boot 3.1.3 with Jackson 2.15.2.
Suggestion
It is suggested that Spring Framework should add support for JsonReadFeature, JsonWriteFeature, StreamWriteFeature in a future release by mapping it to corresponding MapperFeature, or identifying their parent classes like
JacksonFeature
andConfigFeature
, to maintain compatibility with latest Jackson versions when customizing ObjectMapper.The text was updated successfully, but these errors were encountered: