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.
2 Answers
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.
Gsonfrom Google.