diff --git a/src/main/java/vaeke/restcountries/rest/CountryRest.java b/src/main/java/vaeke/restcountries/rest/CountryRest.java index efdcdfec..f9db47ad 100644 --- a/src/main/java/vaeke/restcountries/rest/CountryRest.java +++ b/src/main/java/vaeke/restcountries/rest/CountryRest.java @@ -33,6 +33,7 @@ public class CountryRest { private static final Logger LOG = Logger.getLogger(CountryRest.class); + private static List countries; @GET public Object getCountries() { @@ -169,17 +170,20 @@ private String removeDiacriticalMarks(String string) { } private List getAll() throws IOException { + if(countries != null) return countries; + + LOG.debug("Loading JSON Database"); InputStream is = this.getClass().getClassLoader().getResourceAsStream("countries.json"); Gson gson = new Gson(); JsonReader reader = new JsonReader(new InputStreamReader(is, "UTF-8")); - List list = new ArrayList(); + countries = new ArrayList(); reader.beginArray(); while(reader.hasNext()) { Country country = gson.fromJson(reader, Country.class); - list.add(country); + countries.add(country); } reader.endArray(); reader.close(); - return list; + return countries; } }