title: In Java - How to map resultSet into a complex object?
body: <p>How can I map a resultset from a few tables into a complex object?
  let me elaborate:</p>
  
  <p>Lets say I have these 2 classes:</p>
  
  <pre><code>public class User {
      private int user_id;
      private String fname;
      private String lname;
      //getters setters...
  }
  
  public class Country{
      private String country;
      private ArrayList&lt;User&gt; users;
      }
  </code></pre>
  
  <p>The <code>sql</code> query:</p>
  
  <p>SELECT * FROM users U, Country C WHERE c.user_id = U.id</p>
  
  <p>gives me the following output -</p>
  
  <pre><code>id | fname | lname| country 
  1  | Jack  | Levi |  USA
  1  | Jack  | Levi |  UK
  2  | Mike  | Brown|  Germany
  </code></pre>
  
  <p>How can I map these results into the Country class? 
  I need make from it a <code>Json</code> string to get something like this:</p>
  
  <pre><code>{
  id : 1,
  fname: "jack",
  lname" "levi",
  countries : {"USA", "UK"}
  }
  </code></pre>
  
  <p>Thank you very much!!</p>