I don't understand how to use my custom type bindings to query the database...
I did set up my code generation to map Postgres' json (and jsonb) type to Jackson JsonNode.
It it working well!
I can do:
final List<JsonNode> = ctx.select(TABLE.JSON_FIELD).from(TABLE).fetch(TABLE.JSON_FIELD);
... and I would get an actual List<JsonNode>, which is great!
I can also do:
final JsonNode myJsonNodeInstance = ...;
ctx.update(TABLE).set(TABLE.JSON_FIELD, myJsonNodeInstance).where(...).execute();
However, when I am not directly doing .set(TABLE.JSON_FIELD, myJsonNodeInstance) (which would work), but actually:
final Field<jsonnode> jsonProperty = DSL.field("jsonb_set({0}, {1}, {2})", JsonNode.class, TABLE.JSON_FIELD, DSL.array("name"), myJsonNodeInstance);
this.ctx.update(...).set(TABLE.JSON_FIELD, jsonProperty).where(...),execute();
... I run into:
org.jooq.exception.SQLDialectNotSupportedException: Type class com.fasterxml.jackson.databind.node.ObjectNode is not supported in dialect DEFAULT
This DSLContext isn't aware of my custom binding... and I couldn't find anything related to registering "ForcedTypes" or "Bindings" or anything like that in org.jooq.conf.Settings.
I must either be looking at the wrong place or (most probably), be looking at the problem the wrong way.
What am I missing?
See MCVE at ccjmne/jooq-mcve.
3.11.91.8.0-openjdk42.2.5Following @lukaseder's answer to my question in the docs (http://disq.us/p/21jc2zg), I could get it to work!
I actually used a DataType<JsonNode>, built with the Converter that "powers" the Binding used by TABLE.JSON_FIELD, and DSL#val(Object, DataType<T>) takes care of applying my binding.
Thank you very much for documenting your findings here on Github. I'm sure this will be helpful to future visitors.
Most helpful comment
Thank you very much for documenting your findings here on Github. I'm sure this will be helpful to future visitors.