Skip to content

Instantly share code, notes, and snippets.

@TheSithPadawan
Forked from julianbonilla/GsonTest.java
Created November 29, 2018 18:49
Show Gist options
  • Save TheSithPadawan/f10264f2279947cfe9fbe7af6105f59a to your computer and use it in GitHub Desktop.
Save TheSithPadawan/f10264f2279947cfe9fbe7af6105f59a to your computer and use it in GitHub Desktop.
Read json from file into Gson
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import com.google.gson.Gson;
public class GsonTest {
public static void main(String[] args) throws FileNotFoundException {
String path = "PATH TO YOUR JSON FILE";
BufferedReader bufferedReader = new BufferedReader(new FileReader(path));
Gson gson = new Gson();
Object json = gson.fromJson(bufferedReader, Object.class);
System.out.println(json.getClass());
System.out.println(json.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment