title: Programatically convert yaml string to ConfigurationProperties with Spring Boot 2
body: <p>I have a third party library which provides a class used for ConfigurationProperties, such as the following:</p>
  
  <pre><code>@ConfigurationProperties(prefix = "foo")
  public class AnimalProperties {
  
      private List&lt;Treats&gt; treats = new ArrayList&lt;&gt;();
  ...
  }
  </code></pre>
  
  <p>In Spring Boot 2, what is the easiest way to bind a Yaml string (constructed programatically) to an instance of AnimalProperties? For example, given the string:</p>
  
  <pre><code>treats:
    -
      name: treat1
      flavour: sweet
    -
      name: treat2
      flavour: sour
  </code></pre>
  
  <p>In Spring Boot 1.x this could be done using the YamlConfigurationFactory, however this is no longer present in Spring Boot 2.</p>
  
  <p>For example:</p>
  
  <pre><code>    YamlConfigurationFactory&lt;AnimalProperties&gt; animalConfigFactory = new YamlConfigurationFactory&lt;&gt;(
              AnimalProperties.class);
      animalConfigFactory.setYaml("{ treats: " + treatYalm + " }");
      try {
          animalConfigFactory.afterPropertiesSet();
          treats.addAll(animalConfigFactory.getObject().getTreats());
      }
      ...
  </code></pre>