All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.mrtimeey.herodomainmodel.core.DataLoader Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package io.github.mrtimeey.herodomainmodel.core;

import com.fasterxml.jackson.core.type.TypeReference;
import io.github.mrtimeey.herodomainmodel.model.SuperHero;
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;

final class DataLoader {

   private DataLoader() {
      throw new IllegalStateException("Do not instantiate this class");
   }

   static List getAllHeroes() {
      try (InputStream resource = DataLoader.class.getResourceAsStream("heroes.json")) {
         String inputObject = IOUtils.toString(resource, StandardCharsets.UTF_8);
         TypeReference> typeReference = new TypeReference<>() {
         };
         return ObjectConversionUtils.toObject(inputObject, typeReference).orElse(List.of());
      } catch (IOException e) {
         throw new RuntimeException(e);
      }
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy