Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
UnsupportedMediaTypeException Should Contain Details of the Resolvable Type [SPR-17346] #21880
When a HttpMessageReader can't be found to read a message in org.springframework.web.reactive.function.BodyExtractors#readWithMessageReaders an UnsupportedMediaTypeException is thrown. The UnsupportedMediaTypeException only includes content type from the input message in the exception when the canRead method used to check whether a HttpMessageReader can read the message can return false if the HttpMessageReader doesn't support the resolvable type of the message as well as its' content type.
I encountered the error message:
This was misleading because the problem was nothing to do with not supporting the content type. It was because the SmileFactory that the WebClient had in its exchange strategy did not have the GuavaModule added to it. Had the error message indicated that the type that I was trying to deserialze to could be the problem as well as content type then I think it's likely I would have recognized the root cause without resorting to debugging the code to see what was happening.
I've attached a sample project. The problem should be apparent from running spring.webflux.BodyExtractorsTest or mvn test. There's some extra docs in spring.webflux.BodyExtractorsTest.