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.
Asked
Active
Viewed 2,898 times
0
-
Highly recommending `Gson` from Google. – Rugal Apr 15 '16 at 21:50
-
adding to what others said, google "marshalling json" and "unmarshalling json" – Prefijo Sustantivo Apr 15 '16 at 21:56
-
how to save related objects after parsing from json java? – Iurii B Apr 15 '16 at 22:04
2 Answers
1
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.

gpa
- 2,411
- 6
- 38
- 68
0
-
What about saving using Hibernate\Spring Data with relations between such objects and ids as values of some Object's fields? – Iurii B Apr 15 '16 at 22:07