io.github.mrtimeey.herodomainmodel.core.DataLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of object-finder Show documentation
Show all versions of object-finder Show documentation
Library for finding objects in complex data structures
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);
}
}
}