title: Mapping YAML List to List of Objects in Spring Boot
body: <p>I have a problem similar to that described in <a href="https://stackoverflow.com/questions/32593014/mapping-list-in-yaml-to-list-of-objects-in-spring-boot">Mapping list in Yaml to list of objects in Spring Boot</a> except that I would like to vary the identifier of least one of the fields in my object from the corresponding key name used in YAML. </p>
  
  <p>For example:</p>
  
  <p>YAML File:</p>
  
  <pre><code>config:
      gateways:
          -
              id: 'g0'
              nbrInputs: 128
              nbrOutputs: 128
          -
              id: 'g1'
              nbrInputs: 128
              nbrOutputs: 128
  </code></pre>
  
  <p>Configuration Class:</p>
  
  <pre><code>@Configuration
  @ConfigurationProperties(prefix="config")
  public class GatewayConfig
  {
      List&lt;Gateway&gt; gateways = new ArrayList&lt;Gateway&gt;();
  
      // Getter/Setter for gateways
      // ...
  
      public static class Gateway
      {
          private String id;
  
          @Value("${nbrInputs}")
          private int numInputs;
  
          @Value("${nbrOutputs}")
          private int numOutputs;
  
          // Getters and Setters
          // ...
      }
  }
  </code></pre>
  
  <p>I was hoping that the @Value annotations would allow me to inject the corresponding property values, but this does not seem to work (injection of the 'id' field seems to work just fine).</p>
  
  <p>Is there a way to do this with @Value (or any other annotation)?</p>
  
  <p>Thank you.</p>
  
  <hr>
  
  <p><strong>Edit:</strong>
  Note that I am looking to determine whether I can force a correspondence between a YAML property and a field in the inner POJO <strong>without changing the name of either</strong>. There are several reasons why I might want to do this - e.g. I might not control the format of the YAML file and I would like to use a more descriptive identifier name in my POJO than was used by the author of the YAML file.</p>