datapublica / hibernate-pg-json

Provide json/jsonb mapping for hibernate
MIT License
17 stars 3 forks source link

Storing raw JSON #4

Closed Ramblurr closed 7 years ago

Ramblurr commented 7 years ago

I've been using this library with great success, but up until now I've been serializing Java POJOs into JSON and storing those.

However now I want to cache JSON API responses directly in a jsonb field in a column.

I have the json payload in a String variable and I've declared the property type like so:

    @Type(type = "Json", parameters = {
            @Parameter(name = "type", value = "Object")
    })
    protected Object payload;

The problem is that my string-containing-json is being serialized as a Json String in the column, rather than a Json Object. This makes querying and such against the json structure not possible.

Is it possible to workaround this with the library?

WydD commented 7 years ago

If you manipulate json with its serialized form in your code, you dont need the lib to do that. Just declare a @Column(columnDefinition = "jsonb") and hibernate should transfer the string directly and pg will structure it as json.

Ramblurr commented 7 years ago

Perfect, thanks.