1
I am having problems converting a set of texts in the Json format of the database to a set of Arraylist texts in Java. Follow the code below:
Java model.
public class Sala {
private String professor;
private ArrayList<Aluno> alunos;
//gets e sets...
}
public class Aluno {
private String nome;
private String matricula;
//gets e sets...
}
DAO.java
public ArrayList<Sala> obterInformacoesSala(){
...
try{
while(rs.next()){
Sala s = new Sala();
s.setProfessor(rs.getString("professor"));
s.setAlunos(???); //tipo Json no BD
}
} catch { ... }
}
I am unable to return the data from within the json in the form of arraylist
– Fernando Gatto
For example, inside students has 'name' and 'enrollment'. And I need to take this data, which makes up a json object and fill in an arraylist of the Student type, which is part of the Room
– Fernando Gatto
Good morning, If I understand your doubt I believe this can help you: Your problem is the parse between java objects and json right, there are some libraries that will help you one of it is Jackson and another Gson, follow some examples of use: http://tutorials.jenkov.com/java-json/Jackson-jsonparser.html http://tutorials.jenkov.com/java-json/jackson-jsonparser.html http://tutorials.jenkov.com/java-json/gson-jsonparser.html http://www.javacreed.com/gson-deserialiser-example/
– Andryev Lemes