-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMovieRepository.java
More file actions
36 lines (25 loc) · 838 Bytes
/
Copy pathMovieRepository.java
File metadata and controls
36 lines (25 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package repository;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.lang.reflect.Type;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import model.Movie;
public class MovieRepository {
public List<Movie> listMovies;
public void getData() {
try {
FileReader reader = new FileReader("movie.json");
// Chuyển từ JSON text -> object
Type objectType = new TypeToken<List<Movie>>() {
}.getType();
listMovies = new Gson().fromJson(reader, objectType);
for (Movie movie : listMovies) {
System.out.println(movie);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}