You need to change PatientJsonbelow
public class PatientJson {
String Id, SampleId, Gender;
}
Basically the variable name should be the same as you get in json, or you need to map the variables to json parameters using the SerializedName REF below
import com.google.gson.annotations.SerializedName;
public class PatientJson {
@SerializedName("Id")
String id;
@SerializedName("SampleId")
String sampleId;
@SerializedName("Gender")
String gender;
}
To get data from your json example, you need to do the following
BufferedReader br = new BufferedReader(new FileReader(/mnt/ftp/sample.json));
Type listType = new TypeToken<ArrayList<PatientJson>>() {}.getType();
List<PatientJson> patientList = gson.fromJson(br, listType);
source
share