Thank you Lukas, this was exactly what I needed. Basically, I was confused
about what exactly I was supposed to pass in for the DataType parameter to
DSL.val and that kept me from hitting this answer.

-Daniel

On Mon, May 8, 2017 at 4:50 AM Lukas Eder <[email protected]> wrote:

> Hi Daniel,
>
> The warning message happens because jOOQ doesn't know how to bind your
> Gson JsonObject to a JDBC statement when you pass it to the DSL.val()
> method. You have several options, but they all work the same way. You need
> to tell jOOQ how to bind (or convert) that type. I imagine that you wrote
> your own binding:
>
> https://www.jooq.org/doc/latest/manual/sql-building/queryparts/custom-bindings
>
> ... and then used the code generator configuration to associate that
> binding with your FOO.BAR column:
>
> https://www.jooq.org/doc/latest/manual/code-generation/custom-data-type-bindings
>
> So, you could use DSL.val(Object, Field) or val(Object, DataType) to bind
> your sourceKey:
>
> -
> https://www.jooq.org/javadoc/latest/org/jooq/impl/DSL.html#val-java.lang.Object-org.jooq.Field-
> -
> https://www.jooq.org/javadoc/latest/org/jooq/impl/DSL.html#val-java.lang.Object-org.jooq.DataType-
>
> Next step would be to make this operator reusable:
>
> public static Condition jsonContains(Field<JsonObject> field, JsonObject
> value) {
>     return DSL.condition("{0} @> {1}", field, DSL.val(value, field));
> }
>
>
> And now, completely type safe:
>
> where(jsonContains(FOO.BAR, sourceKey))
>
>
> I hope this helps,
> Lukas
>
> 2017-05-08 6:24 GMT+02:00 Daniel Einspanjer <
> [email protected]>:
>
>> I was struggling a bit with this over the weekend.  FOO is a table with a
>> column BAR which is a JSONB type field.
>> I have the generator hooked up with Gson and the signature for FOO.BAR is
>> a JsonElement.
>>
>> For an example, a row in the table might have the jsonb value for bar:
>>  {"a": 1, "b": 2}
>> And my sourceKey JsonObject would be  {"b": 2}
>>
>> Kept getting errors such as:
>> WARN Caused by: org.jooq.exception.SQLDialectNotSupportedException: Type
>> class com.google.gson.JsonObject is not supported in dialect DEFAULT
>>
>> I tried a few different ways:
>>                             .where(DSL.sql("{0} @> {1}", FOO.BAR,
>> DSL.val(sourceKey)))
>>
>>                             .where(DSL.sql("{0} @> {1}", FOO.BAR,
>> DSL.val(sourceKey)))
>>
>>                             .where(DSL.sql("{0} @> {1}::jsonb", FOO.BAR,
>> DSL.val(sourceKey.toString())))
>>
> --
>> You received this message because you are subscribed to the Google Groups
>> "jOOQ User Group" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>
>
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "jOOQ User Group" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/jooq-user/l-MjmxifiSc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to