Hi Rick,

Thank you very much for your report. That's a very interesting observation.
It doesn't just affect the JSON export, but any interaction with jOOQ. The
DataType associated with any Field is always the original database
DataType, possibly enriched with a custom Converter and/or Binding. The
value exposed to clients is of the type <U> as defined in the Converter
and/or Binding, where <U> defaults to <T>, the database type, if no special
Converter and/or Binding is specified.

So, as you can see, this is the expected behaviour, but of course it is
very misleading, at least in a JSON export context, as consumers of such
JSON documents have no means of guessing that the "type":"BIGINT" was
converted to some custom type.

What should definitely be added is this extra information about the value
having been converted. I've created a feature request for this:
https://github.com/jOOQ/jOOQ/issues/5670

Perhaps, there's also room for exporting the <T> type along with the <U>
type, at least as an opt-in feature, but then the question is why there's a
converter in the first place. I'll still need to think about that latter
idea.

Hope this helps,
Lukas

2016-11-11 13:01 GMT+01:00 <[email protected]>:

> Hi,
>
> when I have following field definition in a table:
>
> public final org.jooq.TableField<my.jooq.json.serialize.test.tables.recor
> ds.TestRecord, org.joda.time.DateTime> TIME_UTC
>     = createField("TIME_UTC",
>                   org.jooq.impl.SQLDataType.BIGINT.nullable(false),
>                   this,
>                   null,
>                   new my.jooq.json.serialize.test.converter.
> DateTimeConverter());
>
> With following Converter:
> public class DateTimeConverter implements Converter<Long, DateTime>
>
> formatJson returns the field definition:
> ...
> "fields":[{"name":"TIME_UTC","type":"BIGINT"},
> ...
>
>
> So far so good, as I assumed that jOOQ would use the underlying database
> type in order to serialize and deserialize the JSON string easily.
>
> But the data part looks like this:
> "2016-06-07T09:00:00.000+02:00"
>
>
> formatJSON converts the custom data type from the fetched record by using
> toString().
> (see: org.jooq.tools.json.JSONValue#toJSONString in github
> <https://github.com/jOOQ/jOOQ/blob/version-3.8.0-branch/jOOQ/src/main/java/org/jooq/tools/json/JSONValue.java#L135>
> )
>
> I expected the json serializer would use the converter to get the database
> type back as a Long value.
> Afterwards the deserializer is not able to turn the String value to BIGINT
> and renders it to a null value.
>
> My question: is this working as expected, is it a bug or is formatJSON not
> intended to be used with custom types?
>
> Thanks in advance
> Rick
>
> --
> 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 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