Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import com.google.gson.FieldNamingPolicy;
- import com.google.gson.Gson;
- import com.google.gson.GsonBuilder;
- import com.google.gson.stream.JsonReader;
- public class GsonReader {
- private String path = "D:\ImportantStuff\Validis\Automation\json.txt";
- public void requestGson() throws FileNotFoundException {
- Gson gson = new GsonBuilder()
- .disableHtmlEscaping()
- .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
- .setPrettyPrinting()
- .serializeNulls()
- .create();
- JsonReader reader = new JsonReader(new FileReader(path));
- //BufferedReader reader = new BufferedReader(new FileReader(path));
- Object json = gson.fromJson(reader, Model.class);
- System.out.println(json.toString());
- }
- }
- import java.io.FileNotFoundException;
- public class Main {
- public static void main(String[] args) throws FileNotFoundException {
- GsonReader r = new GsonReader();
- r.requestGson();
- }
- }
- public class Model {
- private String name;
- private String type;
- private String value;
- public Model(String name, String type, String value){
- this.name = name;
- this.type = type;
- this.value = value;
- }
- public String getName(){
- return name;
- }
- public void setName(String name){
- this.name = name;
- }
- public String getType(){
- return type;
- }
- public void setType(String type){
- this.type = type;
- }
- public String getValue(){
- return value;
- }
- public void setValue(String value){
- this.value = value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement