title: How to add ToXmlGenerator.Feature to Jackson2ObjectMapperBuilderCustomizer?
body: <p>I have the <code>jackson</code> bean configuration below. How can I add the <code>ToXmlGenerator.Feature.WRITE_XML_DECLARATION</code> feature to the builder?</p>
  
  <p>The following does not work:</p>
  
  <pre><code>@Bean
  public Jackson2ObjectMapperBuilderCustomizer initJackson() {
      return (builder) -&gt; builder.modules(new JaxbAnnotationModule())
                  .defaultUseWrapper(false)   
                  .featuresToEnable(ToXmlGenerator.Feature.WRITE_XML_DECLARATION); //invalid!
  
  }
  </code></pre>
  
  <p>Result:</p>
  
  <blockquote>
    <p>Constructor threw exception; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'mappingJackson2XmlHttpMessageConverter'
    defined in class path resource
    [org/springframework/boot/autoconfigure/web/JacksonHttpMessageConvertersConfiguration$MappingJackson2XmlHttpMessageConverterConfiguration.class]:
    Bean instantiation via factory method failed; nested exception is
    org.springframework.beans.BeanInstantiationException: Failed to
    instantiate
    [org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter]:
    Factory method 'mappingJackson2XmlHttpMessageConverter' threw
    exception; nested exception is
    org.springframework.beans.FatalBeanException: Unknown feature class:
    com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator$Feature</p>
  </blockquote>
  
  <p>My initial goal is to add the following line during deserialization:</p>
  
  <p><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code>.</p>
  
  <p>Maybe there is a different way instead of using the <code>ToXmlGenerator</code>?</p>
  
  <p>I also tried the following, but that does also NOT add the xml declaration line:</p>
  
  <pre><code>@Bean
  @Primary
  public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
      XmlMapper mapper = (XmlMapper) builder
              .createXmlMapper(true)
              .build();
  
      mapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
      return mapper;
  }
  </code></pre>