title: Spring Boot Property Yml/Properties with List structure
body: <p>I have looked all over stackoverflow and the net for a solution for this. No solution I have seen works because maybe none of the posts exactly fit my use case which contain a lists inside the file and also an object struture. </p>
  
  <p>Here is a sample as a yaml</p>
  
  <pre><code>teddy.list:
      -
        name: Red
        price: Five
      -
        name: Blue
        price: One
      -
        name: Yellow
        price: Two
      -
        name: Green
        price: Three
  </code></pre>
  
  <p>Here is the same sample as a property file</p>
  
  <pre><code>teddy.list[0].name=Red
  teddy.list[0].price=Five
  teddy.list[1].name=Blue
  teddy.list[1].price=One
  teddy.list[2].name=Yellow
  teddy.list[2].price=Two
  teddy.list[3].name=Green
  teddy.list[3].price=Three
  </code></pre>
  
  <p>I want to be able to supply a teddy.yml or teddy.properties file to my application for configuration.</p>
  
  <p>Here is my class for this:</p>
  
  <pre><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.boot.context.properties.ConfigurationProperties;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.PropertySource;
  import org.springframework.core.env.Environment;
  
  @Configuration
  @PropertySource(name = "props", value = "classpath:teddy.yml", ignoreResourceNotFound = false)
  @ConfigurationProperties(prefix = "teddy")
  public class TeddyBearConfig {
  
      @Autowired
      Environment env;
  
      @Value("${teddy.list}")
      private TeddyBear[] teddyBears;
  
      public TeddyBear[] getTeddyBears() {
          return teddyBears;
      }
  
      public void setTeddyBears(TeddyBear[] teddyBears) {
          this.teddyBears = teddyBears;
      }
  
      public static class TeddyBear {
          private String name;
          private String price;
  
          public TeddyBear() {
  
          }
  
          public TeddyBear(String name, String price) {
              this.name = name;
              this.price = price;
          }
  
          public String getName() {
              return name;
          }
  
          public void setName(String name) {
              this.name = name;
          }
  
          public String getPrice() {
              return price;
          }
  
          public void setPrice(String price) {
              this.price = price;
          }
      }
  }
  </code></pre>
  
  <p>I've tried this setup, using the environment to try and access the properties, removing the prefix, declaring a bean of "PropertySourcesPlaceholderConfigurer".</p>
  
  <p>With the current code, spring throws a IllegalStateException because it cannot convert java.lang.string to my TeddyBear class.</p>