Trying to tritely read the JSON file, followed by creating a class object, but nothing comes out, BufferedReader does not even read the file, although in the examples it is directly transmitted to the GSON, dependency in the POM file added ..
JSON itself of this format
{
"Student": [{
"Name": "Ivan",
"SURNAME": "Ivanov",
}, {
"Name": "Peter",
"SURNAME": "Ivanov",
}]
}
created two classes
Public Class Pojostudents
{
String Name;
String Surname;
}
and
Public Class GeneralStudents {
List & lt; Pojostudents & gt; General;
}
Class Main
import java.io.bufferedReader;
Import java.io.FileReader;
Import com.google.gson.gson;
Public Class Main.
{
Public Static Void Main (String [] Args) Throws Exception
{
GSON GSON = NEW GSON ();
BufferedReader Br = New BufferedReader (New FileReader ("D: \\ Students.json"));
GeneralStudents Students = Gson.Fromjson (Br, GeneralStudents.class);
}
}
Answer 1, Authority 100%
You have the wrong variable name in the main class:
Public Class GeneralStudents {
List & lt; Pojostudents & gt; General;
}
should be instead of Student
instead of general