Jooq array as collection
<p>I want to use Collections in java instead of arrays to serialize postgreSQL arrays. Such as int[], varchar(256)[] to java Collection and Collection.</p>

<p>I use jooq 3.6.2, java 8 and postgresql 9.2.9.</p>

<p>I tried to implement custom binding:</p>

<pre><code>public class PostgresArrayBinding implements Binding&lt;Object, Collection&gt; {

    @Override
    public Converter&lt;Object, Collection&gt; converter() {
        return new Converter&lt;Object, Collection&gt;() {
            @Override
            public Collection from(final Object dbObj) {
                return dbObj == null ? null : new ArrayList&lt;&gt;(Arrays.asList((Object[])dbObj));
            }

            @Override
            public Object to(final Collection userObject) {
                return userObject == null ? null : "ARRAY[" + Joiner.on(',').join(userObject) + "]";
            }

            @Override
            public Class&lt;Object&gt; fromType() {
                return Object.class;
            }

            @Override
            public Class&lt;Collection&gt; toType() {
                return Collection.class;
            }
        };
    }

    @Override
    public void sql(final BindingSQLContext&lt;Collection&gt; ctx) throws SQLException {
        ctx.render().visit(DSL.val(ctx.convert(converter()).value())).sql("::ARRAY");
    }

    @Override
    public void register(final BindingRegisterContext&lt;Collection&gt; ctx) throws SQLException {
        ctx.statement().registerOutParameter(ctx.index(), Types.ARRAY);
    }

    @Override
    public void set(final BindingSetStatementContext&lt;Collection&gt; ctx) throws SQLException {
        ctx.statement().setString(ctx.index(), Objects.toString(ctx.convert(converter()).value(), null));
    }

    @Override
    public void set(final BindingSetSQLOutputContext&lt;Collection&gt; ctx) throws SQLException {
        throw new SQLFeatureNotSupportedException();
    }

    @Override
    public void get(final BindingGetResultSetContext&lt;Collection&gt; ctx) throws SQLException {
        ctx.convert(converter()).value(ctx.resultSet().getString(ctx.index()));
    }

    @Override
    public void get(final BindingGetStatementContext&lt;Collection&gt; ctx) throws SQLException {
        ctx.convert(converter()).value(ctx.statement().getString(ctx.index()));
    }

    @Override
    public void get(final BindingGetSQLInputContext&lt;Collection&gt; ctx) throws SQLException {
        throw new SQLFeatureNotSupportedException();
    }
}
</code></pre>

<p>And <em>jooq-config.xml</em>:</p>

<pre><code>&lt;configuration&gt;
...
&lt;generator&gt;
    &lt;database&gt;
        &lt;name&gt;org.jooq.util.postgres.PostgresDatabase&lt;/name&gt;
        &lt;includes&gt;.*&lt;/includes&gt;
        &lt;excludes&gt;schema_version&lt;/excludes&gt;
        &lt;inputSchema&gt;public&lt;/inputSchema&gt;            
        &lt;customTypes&gt;
            ...
            &lt;customType&gt;
                &lt;name&gt;ARRAY&lt;/name&gt;
                &lt;type&gt;java.util.Collection&lt;/type&gt;
                &lt;binding&gt;ru.fabit.contingent.configuration.persistence.PostgresArrayBinding&lt;/binding&gt;
            &lt;/customType&gt;                
        &lt;/customTypes&gt;

        &lt;forcedTypes&gt;
            ...
            &lt;forcedType&gt;
                &lt;name&gt;ARRAY&lt;/name&gt;
                &lt;expression&gt;.*_ARRAY&lt;/expression&gt;
                &lt;types&gt;.*&lt;/types&gt;
            &lt;/forcedType&gt;                
        &lt;/forcedTypes&gt;
    &lt;/database&gt;
    &lt;generate&gt;
        &lt;records&gt;true&lt;/records&gt;
        &lt;interfaces&gt;true&lt;/interfaces&gt;
        &lt;relations&gt;true&lt;/relations&gt;
        &lt;validationAnnotations&gt;true&lt;/validationAnnotations&gt;
    &lt;/generate&gt;
    &lt;target&gt;
        &lt;packageName&gt;ru.fabit.contingent.models.generated&lt;/packageName&gt;
        &lt;directory&gt;src/main/java/&lt;/directory&gt;
    &lt;/target&gt;
&lt;/generator&gt;
&lt;/configuration&gt;
</code></pre>

<p>SQL:</p>

<p>CREATE TABLE array_tests(string_array varchar(256)[]);</p>

<p>And I had error in generated class: </p>

<pre><code>public final TableField&lt;ArrayTestsRecord, Collection[]&gt; STRING_ARRAY = createField("string_array", org.jooq.impl.DefaultDataType.getDefaultDataType("java.util.Collection").getArrayDataType(), this, "", new PostgresArrayBinding());
</code></pre>

<p><em>no suitable method found for createField(String,DataType,ArrayTests,String,PostgresArrayBinding)</em></p>

<p>Any ideas?</p>