Reputation: 1
How to convert from json into java objects data and save into database? As I understand the only one way is using DTO? Or I'm wrong? There is application which returns something like "dump" of database. My aim is to deserialize it and save into database. The problems: in some "object" fields there are ids, there are some exceptions regarding constraints during saving into database.
Upvotes: 0
Views: 3112
Reputation: 1982
Another option is to use Jackson, some examples could be found here. We use it in production for almost two years and find it powerful and handy.
Upvotes: 0
Reputation: 2451
You need to use google Gson Api, following links show how-tos: http://www.mkyong.com/java/how-do-convert-java-object-to-from-json-format-gson-api/
Make sure DTO implements Serializable interface before persisting object into database... i would rather serialize on file system and store path into database because i do not like storing in CLOB or BLOB columns... too expensive queries.
Upvotes: 1