Guest User

Untitled

a guest
Feb 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #JSON#
  2. JSON is short for JavaScript Object Notation.
  3. JSON is a popular data exchange format between browsers and web servers because the browsers can parse JSON into JavaScript objects natively.
  4. On the server, however, JSON needs to be parsed and generated using JSON APIs.
  5.  
  6. #Jackson#
  7. Jackson is a Java JSON API which provides several different ways to work with JSON.
  8.  
  9. #Adding Jackson to Project#
  10. <dependency>
  11. <groupId>com.fasterxml.jackson.core</groupId>
  12. <artifactId>jackson-core</artifactId>
  13. <version>2.9.4</version>
  14. </dependency>
  15. <dependency>
  16. <groupId>com.fasterxml.jackson.core</groupId>
  17. <artifactId>jackson-annotations</artifactId>
  18. <version>2.9.4</version>
  19. </dependency>
  20. <dependency>
  21. <groupId>com.fasterxml.jackson.core</groupId>
  22. <artifactId>jackson-databind</artifactId>
  23. <version>2.9.4</version>
  24. </dependency>
  25.  
  26. #Jackson ObjectMapper Example#
  27. ```
  28. ObjectMapper objectMapper = new ObjectMapper();
  29.  
  30. String carJson =
  31. "{ \"brand\" : \"Mercedes\", \"doors\" : 5 }";
  32.  
  33. try {
  34. Car car = objectMapper.readValue(carJson, Car.class);
  35.  
  36. System.out.println("car brand = " + car.getBrand());
  37. System.out.println("car doors = " + car.getDoors());
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. ```
Add Comment
Please, Sign In to add comment