title: How to read from YAML file in java?
body: <p>I have YAML file like this..</p>
  <pre><code>Product:
   ProductA:
    Suite:
      SuiteName_A:
        Environment_1: [&quot;A&quot;,&quot;B&quot;,&quot;C&quot;]
        Environment_2: [&quot;X&quot;,&quot;Y&quot;,&quot;Z&quot;]
      SuiteName_B:
        Environment_1: [&quot;E&quot;,&quot;F&quot;,&quot;G&quot;]
        Environment_2: [&quot;K&quot;,&quot;L&quot;,&quot;M&quot;]
   ProductB:
    Suite:
      SuiteName_K:
        Environment_1: [&quot;A1&quot;,&quot;B2&quot;,&quot;C3&quot;]
        Environment_2: [&quot;X1&quot;,&quot;Y1&quot;,&quot;Z1&quot;]
  </code></pre>
  <p>Edited----
  I have created few classes as I read in some read article and here what i came up with..</p>
  <p>Environment Class</p>
  <pre><code>    package Configuration;
  
  import java.util.ArrayList;
  
  public class Environment {
      private ArrayList&lt;String&gt; Environment_1;
      private ArrayList&lt;String&gt; Environment_2;
  
      public ArrayList&lt;String&gt; getEnvironment_1() {
          return Environment_1;
      }
  
      public void setEnvironment_1(ArrayList&lt;String&gt; Environment_1) {
          this.Environment_1 = Environment_1;
      }
  
      public ArrayList&lt;String&gt; getEnvironment_2() {
          return Environment_2;
      }
  
      public void setEnvironment_2(ArrayList&lt;String&gt; Environment_2) {
          this.Environment_1 = Environment_2;
      }
  }
  </code></pre>
  <p>SuitName Class</p>
  <pre><code>    package Configuration;
  
  import java.util.HashMap;
  
  public class SuiteNames {
      private HashMap&lt;String,Environment&gt; Suite;
  
      public HashMap&lt;String, Environment&gt; getSuite() {
          return Suite;
      }
  
      public void setSuite(HashMap&lt;String, Environment&gt; suite) {
          Suite = suite;
      }
  }
  </code></pre>
  <p>Product Class</p>
  <pre><code>    package Configuration;
  
  import java.util.HashMap;
  
  public class Product {
      private HashMap&lt;String,SuiteNames&gt; Product;
  
      public HashMap&lt;String, SuiteNames&gt; getProduct() {
          return Product;
      }
  
      public void setProduct(HashMap&lt;String, SuiteNames&gt; product) {
          this.Product = product;
      }
  }
  </code></pre>
  <p>Main Class</p>
  <pre><code>    package Configuration;
  
  import org.yaml.snakeyaml.Yaml;
  
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.InputStream;
  
  public class DbClass {
  
      public static void main(String[] args) throws FileNotFoundException {
          Yaml yaml = new Yaml();
          InputStream inputStream = new FileInputStream(&quot;path&quot;);
          System.out.println(inputStream);
          Product product = yaml.loadAs(inputStream,Product.class);
          System.out.println(product.getProduct());
      }
  }
  </code></pre>
  <p>This gives following error:</p>
  <pre><code>     Exception in thread &quot;main&quot; Cannot create property=Product for JavaBean=Configuration.Product@4c98385c
   in 'reader', line 1, column 1:
      Product:
      ^
  Unable to find property 'Product' on class: Configuration.Product
   in 'reader', line 2, column 3:
        Check-in:
        ^
  
      at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:270)
      at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:149)
      at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:309)
      at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:216)
      at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:205)
      at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:164)
      at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:148)
      at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:525)
      at org.yaml.snakeyaml.Yaml.loadAs(Yaml.java:519)
      at Configuration.DbClass.main(DbClass.java:17)
  Caused by: org.yaml.snakeyaml.error.YAMLException: Unable to find property 'Product' on class: Configuration.Product
      at org.yaml.snakeyaml.introspector.PropertyUtils.getProperty(PropertyUtils.java:159)
      at org.yaml.snakeyaml.introspector.PropertyUtils.getProperty(PropertyUtils.java:148)
      at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.getProperty(Constructor.java:287)
      at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:208)
      ... 9 more
  </code></pre>
  <p>I want get the list of Environent names and to store this in a list. I am aware using jackson api. But I don't know how to map this data to class.
  I am using servlets and inside the servlet i want to have a java method to get the list of strings.</p>