title: How to convert array of composite type to array of java objects with jdbc and Postgres?
body: <p>I have an array of composite type. Let's say it looks like this:</p>
  
  <pre><code>CREATE TYPE hobbie AS (
    name VARCHAR,
    description VARCHAR
  );
  
  CREATE TABLE person (
      id SERIAL,
      hobbie hobbie[]
  );
  </code></pre>
  
  <p>Now I need to retrieve hobbies of person from postgres and convert them into java object which looks like this:</p>
  
  <pre><code>public class Hobbie {
      String name;
      String description;
  }
  </code></pre>
  
  <p>The only thing which I was able to do with jdbc is to convert array get to result set with hobbies as String like this <code>("basketball","the best game")</code>. How can I convert it to java object using jdbc?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Here is my code to work with postgres array using jdbc:</p>
  
  <pre><code>ResultSet hobbies = rs.getArray("hobbies").getResultSet
  while (hobbies.next()){
      hobbies.getString(1) // returns some index or I don't know
      hobbies.getObject(2) // returns PgValue with value == String ("basketball","the best game")
      hobbies.getObject(2)  // obviously returns String with the same value
      hobbies.getArray(2)   // returns something strange
      hobbies.getObject(2, Hobbie.class) // throws unsupported conversion to class com.test.Hobbie. Maybe there is a way to register custom converter, but I didn't find any
   }
  </code></pre>