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.

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.html


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.

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverter.html

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need