4

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 .

2 Answers 2

6

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/

Sign up to request clarification or add additional context in comments.

2 Comments

Helpful .. Thanks .
You need an external dependency for this approach
1

There's no way. You can save it parsing the JSON to String ( Ex: JSON.stringify() ) and when you query the info , parse the string to JSON (Ex: JSON.parse() )

JSON.stringify: https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/JSON/stringify

JSON.parse: https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/JSON/parse

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.