Using JPA and JSON serialization

I would like to have a JPA object that has a GSon object as a field / attribute. For instance:

@Entity
public class MyEntity {

    private JsonObject myObject;

    public JsonObject getObject() {
        return myObject;
    }

    public void setObject(JsonObject obj) {
        myObject = obj;
    }

}

I am not familiar with how this manager is maintained. Ideally, it would be like a JSON string, but essentially I want to hide how things are stored from the public API. I could do this potentially using an inner class that has type methods String getObject()that my outer class passes and does JSON analysis to return a JsonObject, but I am wondering if there is another way.

+3
source share
2 answers

It might be wise to just store them as strings (varchars) in db. Just do GSon serialization / deserialization in your manager or dao.

+2

JsonObject Serializable, , , , , , . .

, : JAXB JPA

+1

Source: https://habr.com/ru/post/1763137/


All Articles