Advertisement
Guest User

Untitled

a guest
Dec 27th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.70 KB | None | 0 0
  1. [
  2. {
  3. "elementaryProductId":1,
  4. "bonusMalus":30,
  5. "deductible":500,
  6. "comprehensive":1,
  7. "partial":0,
  8. "legacyPremium":130,
  9. "product":{
  10. "productId":2,
  11. "garage":"true",
  12. "constructionYear":1990,
  13. "region":"East",
  14. "dateOfBirthYoungest":"1983-06-22",
  15. "objectValue":25000,
  16. "type":"Car",
  17. "insuredObject":{
  18. "name":"Car",
  19. "ownersName":"Jovana",
  20. "mileage":300000,
  21. "engineCapacity":120
  22. },
  23. "salesProduct":{
  24. "salesProductId":3,
  25. "currency":"EUR",
  26. "contractStart":"2011-01-01",
  27. "contractEnd":"2012-01-01"
  28. },
  29. "productType":"Car"
  30. }
  31. },
  32. {
  33. "elementaryProductId":1,
  34. "bonusMalus":5,
  35. "deductible":100,
  36. "comprehensive":1,
  37. "partial":0,
  38. "legacyPremium":75.38,
  39. "product":{
  40. "productId":2,
  41. "garage":"true",
  42. "constructionYear":2005,
  43. "region":"East",
  44. "dateOfBirthYoungest":"1999-06-22",
  45. "objectValue":30000,
  46. "type":"Car",
  47. "insuredObject":{
  48. "name":"Car",
  49. "ownersName":"Jelena",
  50. "mileage":300000,
  51. "engineCapacity":210
  52. },
  53. "salesProduct":{
  54. "salesProductId":3,
  55. "currency":"EUR",
  56. "contractStart":"2013-01-01",
  57. "contractEnd":"2014-01-01"
  58. },
  59. "productType":"Car"
  60. }
  61. },
  62. {
  63. "elementaryProductId":1,
  64. "bonusMalus":-8,
  65. "deductible":0,
  66. "comprehensive":1,
  67. "partial":0,
  68. "legacyPremium":111,
  69. "product":{
  70. "productId":2,
  71. "garage":"true",
  72. "constructionYear":1987,
  73. "region":"East",
  74. "dateOfBirthYoungest":"1977-09-22",
  75. "objectValue":4000,
  76. "type":"Car",
  77. "insuredObject":{
  78. "name":"Car",
  79. "ownersName":"Jelena",
  80. "mileage":300000,
  81. "engineCapacity":120
  82. },
  83. "salesProduct":{
  84. "salesProductId":3,
  85. "currency":"EUR",
  86. "contractStart":"2012-01-01",
  87. "contractEnd":"2013-01-01"
  88. },
  89. "productType":"Car"
  90. }
  91. },
  92. {
  93. "elementaryProductId":1,
  94. "bonusMalus":0,
  95. "deductible":0,
  96. "comprehensive":1,
  97. "partial":0,
  98. "legacyPremium":50,
  99. "product":{
  100. "productId":2,
  101. "garage":"true",
  102. "constructionYear":1999,
  103. "region":"East",
  104. "dateOfBirthYoungest":"1942-10-22",
  105. "objectValue":15000,
  106. "type":"Car",
  107. "insuredObject":{
  108. "name":"Car",
  109. "ownersName":"Bojana",
  110. "mileage":300000,
  111. "engineCapacity":160
  112. },
  113. "salesProduct":{
  114. "salesProductId":3,
  115. "currency":"DIN",
  116. "contractStart":"2012-01-01",
  117. "contractEnd":"2013-01-01"
  118. },
  119. "productType":"Car"
  120. }
  121. },
  122. {
  123. "elementaryProductId":1,
  124. "bonusMalus":0,
  125. "deductible":1000,
  126. "comprehensive":1,
  127. "partial":0,
  128. "legacyPremium":70,
  129. "product":{
  130. "productId":2,
  131. "garage":"false",
  132. "constructionYear":2011,
  133. "region":"East",
  134. "dateOfBirthYoungest":"1967-12-22",
  135. "objectValue":10000,
  136. "type":"Car",
  137. "insuredObject":{
  138. "name":"Car",
  139. "ownersName":"Tamara",
  140. "mileage":55000,
  141. "engineCapacity":70
  142. },
  143. "salesProduct":{
  144. "salesProductId":3,
  145. "currency":"EUR",
  146. "contractStart":"2012-01-01",
  147. "contractEnd":"2013-01-01"
  148. },
  149. "productType":"Car"
  150. }
  151. },
  152. {
  153. "elementaryProductId":1,
  154. "bonusMalus":-15,
  155. "deductible":1500,
  156. "comprehensive":1,
  157. "partial":0,
  158. "legacyPremium":130,
  159. "product":{
  160. "productId":2,
  161. "garage":"true",
  162. "constructionYear":1970,
  163. "region":"West",
  164. "dateOfBirthYoungest":"1952-06-22",
  165. "objectValue":35000,
  166. "type":"Car",
  167. "insuredObject":{
  168. "name":"Car",
  169. "ownersName":"Tijana",
  170. "mileage":15000,
  171. "engineCapacity":110
  172. },
  173. "salesProduct":{
  174. "salesProductId":3,
  175. "currency":"EUR",
  176. "contractStart":"2011-01-01",
  177. "contractEnd":"2012-01-01"
  178. },
  179. "productType":"Car"
  180. }
  181. },
  182. {
  183. "elementaryProductId":1,
  184. "bonusMalus":-2,
  185. "deductible":1500,
  186. "comprehensive":1,
  187. "partial":0,
  188. "legacyPremium":120,
  189. "product":{
  190. "productId":2,
  191. "garage":"true",
  192. "constructionYear":2003,
  193. "region":"East",
  194. "dateOfBirthYoungest":"1964-06-22",
  195. "objectValue":60000,
  196. "type":"Car",
  197. "insuredObject":{
  198. "name":"Car",
  199. "ownersName":"Dubravka",
  200. "mileage":300000,
  201. "engineCapacity":110
  202. },
  203. "salesProduct":{
  204. "salesProductId":3,
  205. "currency":"EUR",
  206. "contractStart":"2014-01-01",
  207. "contractEnd":"2015-01-01"
  208. },
  209. "productType":"Car"
  210. }
  211. },
  212. {
  213. "elementaryProductId":1,
  214. "bonusMalus":0,
  215. "deductible":0,
  216. "comprehensive":1,
  217. "partial":0,
  218. "legacyPremium":130,
  219. "product":{
  220. "productId":2,
  221. "garage":"false",
  222. "constructionYear":2013,
  223. "region":"East",
  224. "dateOfBirthYoungest":"1988-06-12",
  225. "objectValue":13000,
  226. "type":"Car",
  227. "insuredObject":{
  228. "name":"Car",
  229. "ownersName":"Tanja",
  230. "mileage":0,
  231. "engineCapacity":75
  232. },
  233. "salesProduct":{
  234. "salesProductId":3,
  235. "currency":"EUR",
  236. "contractStart":"2013-01-01",
  237. "contractEnd":"2014-01-01"
  238. },
  239. "productType":"Car"
  240. }
  241. }
  242. ]
  243.  
  244. public class SalesProductClass {
  245. private int salesProductId;
  246. private String currency;
  247. private Date contractStart;
  248. private Date contractEnd;
  249.  
  250. // getters & setters methods
  251. }
  252.  
  253. public class InsuredClass {
  254. private String name;
  255. private String ownersName;
  256. private int mileage;
  257. private int engineCapacity;
  258.  
  259. // getters & setters methods
  260. }
  261.  
  262. public class ProductClass {
  263. private int productId;
  264. private String garage;
  265. private int constructionYear;
  266. private String region;
  267. private Date dateOfBirthYoungest;
  268. private int objectValue;
  269. private String type;
  270. private InsuredClass insuredObject;
  271. private SalesProductClass salesProduct;
  272. private String productType;
  273.  
  274. // getters & setters methods
  275. }
  276.  
  277. public class SomeRootClass {
  278. private int elementaryProductId;
  279. private int bonusMalus;
  280. private int deductible;
  281. private int comprehensive;
  282. private int partial;
  283. private int legacyPremium;
  284. private ProductClass product;
  285.  
  286. // getters & setters methods
  287. }
  288.  
  289. <dependency>
  290. <groupId>com.google.code.gson</groupId>
  291. <artifactId>gson</artifactId>
  292. <version>2.3</version>
  293. </dependency>
  294.  
  295. Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
  296.  
  297. TypeToken<List<SomeRootClass>> token = new TypeToken<List<SomeRootClass>>() {};
  298. List<SomeRootClass> funds = gson.fromJson(jsonData, token.getType());
  299.  
  300. public String readJsonFile(String fileNamePath) {
  301. BufferedReader br = null;
  302. String line = "";
  303. String data = "";
  304.  
  305. try {
  306. br = new BufferedReader(new FileReader(fileNamePath));
  307. while ((line = br.readLine()) != null) {
  308. data += line;
  309. }
  310. } catch (Exception e) {
  311. e.printStackTrace();
  312. } finally {
  313. try {
  314. if (br != null) {
  315. br.close();
  316. }
  317. } catch (Exception e2) {
  318. e2.printStackTrace();
  319. }
  320. }
  321.  
  322. return data;
  323. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement