Spring Certified Professional 2023 · Free Practice Question Medium
Question 10
Which of the following are pre-enabled HttpMessageConverters? (select 2)
-
A
XlsHttpMessageConverter -
B
Jaxb2RootElementHttpMessageConverter -
C
MappingJackson2HttpMessageConverter -
D
CsvHttpMessageConverter
Reveal correct answers
Correct answers: B, C
Explanation
The Default Message Converters
By default, the following HttpMessageConverters instances are pre-enabled:
ByteArrayHttpMessageConverter – converts byte arrays
StringHttpMessageConverter – converts Strings
ResourceHttpMessageConverter – converts org.springframework.core.io.Resource for any type of octet-stream
SourceHttpMessageConverter – converts javax.xml.transform.Source
FormHttpMessageConverter – converts form data to/from a MultiValueMap<String, String>
Jaxb2RootElementHttpMessageConverter – converts Java objects to/from XML (added only if JAXB2 is present on the classpath)
MappingJackson2HttpMessageConverter – converts JSON (added only if Jackson 2 is present on the classpath)
MappingJacksonHttpMessageConverter – converts JSON (added only if Jackson is present on the classpath)
AtomFeedHttpMessageConverter – converts Atom feeds (added only if Rome is present on the classpath)
RssChannelHttpMessageConverter – converts RSS feeds (added only if Rome is present on the classpath)
https://www.baeldung.com/spring-httpmessageconverter-rest#2-the-default-message-converters
Springdoc:
public class MappingJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter
Implementation of HttpMessageConverter that can read and write JSON using Jackson 2.x's ObjectMapper.
public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessageConverter<Object>
Implementation of HttpMessageConverter that can read and write XML using JAXB2.
This converter can read classes annotated with XmlRootElement and XmlType, and write classes annotated with XmlRootElement, or subclasses thereof.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
