To expand a bit, Cayenne basically provides a way to map DB-specific JSON 
columns to "org.apache.cayenne.value.Json". This gives a (hopefully) smooth 
experience reading and writing such values. How to use it:

1. Ensure your DB supports native JSON type (e.g. Postgres)
2. Map your DbAttribute as type "OTHER" 
3. Map your ObjAttribute as "org.apache.cayenne.value.Json"

2 & 3 would happen automatically on reverse-engineering if you are using 
DB-first flow. "org.apache.cayenne.value.Json" is simply a String wrapper. It 
intentionally doesn't have any parsing logic. Its purpose is to be a performant 
dependency-free container to pass JSON payload between the app and DB. If you 
need JSON as a tree, you may take a few more steps:

4. Pick a JSON parser such as Jackson.
5. Map ObjAttribute as a type supported by that parser (e.g. JsonNode in 
Jackson)
6. Write and register a custom "ValueObjectType<JsonNode, Json>" [1]
7. There is even a way to use DB-specific functions to query JSON [2] 

@Nikita: is it possible to apply custom functions in the WHERE clause as well?

Andrus

[1] https://cayenne.apache.org/docs/4.2/cayenne-guide/#value-object-type 
<https://cayenne.apache.org/docs/4.2/cayenne-guide/#value-object-type>
[2] 
https://github.com/apache/cayenne-examples/blob/master/cayenne-jdbc-type-other/src/main/java/org/apache/cayenne/demo/JsonTestCommand.java#L59



> On Oct 13, 2020, at 11:07 AM, Nikita Timofeev <ntimof...@objectstyle.com> 
> wrote:
> 
> Hi Markus,
> 
> No docs for that yet, but here's an example of new types usage:
> 
> https://github.com/apache/cayenne-examples/tree/master/cayenne-jdbc-type-other
> 
> On Tue, Oct 13, 2020 at 10:41 AM Markus Reich <reich.mar...@gmail.com> wrote:
>> 
>> Hi Andrus,
>> 
>> is there an example or doc for the support of JSON types?
>> 
>> regards
>> Meex
>> 
>> Am Di., 13. Okt. 2020 um 08:48 Uhr schrieb Andrus Adamchik <
>> and...@objectstyle.org>:
>> 
>>> 4.2.M2 release is out [1]. A few cool things in this release:
>>> 
>>> * Support for JSON and geospatial value types.
>>> * Ordering on aggregate functions and in-memory evaluation of aggregate
>>> expressions.
>>> * Modeler support for downloading JDBC drivers from maven central.
>>> * Runtime changes that may be less obvious to the end user, but allow to
>>> handle a variety of edge cases.
>>> * Bug fixes
>>> 
>>> Also looks like we are pretty close to beta freeze. The main scope of 4.2
>>> is done, though of course improvement ideas keep popping up all the time,
>>> especially now that the new stack significantly expanded our SQL vocabulary
>>> and JDBC capabilities. E.g. one such idea is using EXISTS instead of JOIN +
>>> DISTINCT for to-many conditions [2].
>>> 
>>> Enjoy M2!
>>> 
>>> Andrus
>>> 
>>> [1] https://cayenne.apache.org/2020/10/cayenne-42m2-released/
>>> [2] https://issues.apache.org/jira/browse/CAY-2684
>> 
>> 
>> 
>> --
>> *Markus Reich*
>> Waldweg 62
>> 6393 St. Ulrich am Pillersee
>> www.markusreich.at / www.meeximum.at
>> markus.re...@markusreich.at
> 
> 
> 
> -- 
> Best regards,
> Nikita Timofeev

Reply via email to