Skip to content
Advertisement

How to store json object in a column of mysql using spring boot/java

Requirement is like that a json object is send from postman and i need to receive it on a restcontroller and save that whole json object as it is to the mysql database Table Column(in one/single column) using spring boot.

{
    "name" : "abc",
    "address : "xyz"
}

assume the above json object is send from postman to a spring boot restcontroller. How can i save that json object in a column of a table .

Advertisement

Answer

MySQL supports JSON column types. https://dev.mysql.com/doc/refman/8.0/en/json.html

So, assuming you will be using json column type for your requirement, you can follow below articles. I was able to do this for postgres as well, works very well for me, the instructions are pretty straightforward.

https://vladmihalcea.com/how-to-map-json-objects-using-generic-hibernate-types/ https://vladmihalcea.com/java-map-json-jpa-hibernate/

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement