Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4.  
  5. import com.google.gson.FieldNamingPolicy;
  6. import com.google.gson.Gson;
  7. import com.google.gson.GsonBuilder;
  8. import com.google.gson.stream.JsonReader;
  9.  
  10. public class GsonReader {
  11.  
  12. private String path = "D:\ImportantStuff\Validis\Automation\json.txt";
  13.  
  14. public void requestGson() throws FileNotFoundException {
  15. Gson gson = new GsonBuilder()
  16. .disableHtmlEscaping()
  17. .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
  18. .setPrettyPrinting()
  19. .serializeNulls()
  20. .create();
  21. JsonReader reader = new JsonReader(new FileReader(path));
  22. //BufferedReader reader = new BufferedReader(new FileReader(path));
  23. Object json = gson.fromJson(reader, Model.class);
  24. System.out.println(json.toString());
  25. }
  26. }
  27.  
  28. import java.io.FileNotFoundException;
  29.  
  30. public class Main {
  31.  
  32. public static void main(String[] args) throws FileNotFoundException {
  33. GsonReader r = new GsonReader();
  34. r.requestGson();
  35.  
  36. }
  37.  
  38. }
  39.  
  40. public class Model {
  41. private String name;
  42. private String type;
  43. private String value;
  44.  
  45. public Model(String name, String type, String value){
  46. this.name = name;
  47. this.type = type;
  48. this.value = value;
  49. }
  50.  
  51. public String getName(){
  52. return name;
  53. }
  54.  
  55. public void setName(String name){
  56. this.name = name;
  57. }
  58.  
  59. public String getType(){
  60. return type;
  61. }
  62.  
  63. public void setType(String type){
  64. this.type = type;
  65. }
  66.  
  67. public String getValue(){
  68. return value;
  69. }
  70.  
  71. public void setValue(String value){
  72. this.value = value;
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement