perplexhub / rsql-jpa-specification

Java Library to Translate RSQL into Spring Data JPA Specification and QueryDSL Predicate
MIT License
223 stars 61 forks source link

Support json and json columns #57

Open messaoudi-mounir opened 2 years ago

messaoudi-mounir commented 2 years ago

Hi, i use vladmihalcea/hibernate-types to define json and jsonb columns using Postgresql as database.

Here an example:

`

@TypeDefs({ @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class), @TypeDef(name = "json", typeClass = JsonNodeStringType.class) }) public class MyEntity {

.. .. @Column(name = "segment", columnDefinition = "jsonb") @Type(type = "jsonb") private Set< String > segment; ... .. `

The filter is not working ?filter=segment=like=test and i get an error: "com.fasterxml.jackson.core.JsonParseException: Unexpected character ('%' (code 37)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: (String)\"%[test]%\"; line: 1, column: 2]; nested exception is java.lang.IllegalArgumentException: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('%' (code 37)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: (String)\"%[test]%\"; line: 1, column: 2]"

Is there any way to support json/jsonb columns types query ?

thanks

perplexhub commented 2 years ago

Do you have the sql query?

chriseteka commented 1 year ago

It is interesting this issue is open already, I had a need for this, and will like to research it in my free time.

Do you have the sql query? I saw some sample queries here.


-- Give me params.name (text) from the events table
select params->>'name' from events;

-- Find only events with a specific name select * from events where params->>'name' = 'Click Button';

-- Give me the first index of a JSON array select params->ids->0 from events;

-- Find users where preferences.beta is true (boolean) -- This requires type casting preferences->'beta' from json to boolean select preferences->'beta' from users where (preferences->>'beta')::boolean is true;

l-martini commented 1 year ago

Hi, many thanks for this wonderful lib.

Is there no plan in the short future to add support for jsonb columns? @perplexhub Did you find some workaround to get your job done? @chriseteka

Many thanks