// Path: src/main/java/io/github/sskorol/utils/ReflectionUtils.java
// @SuppressWarnings("unchecked")
// public static <T> Class<T[]> castToArray(final Class<T> entityClass) {
//     return (Class<T[]>) (entityClass.isArray() ? entityClass : Array.newInstance(entityClass, 1).getClass());
// }
// 
// Path: src/main/java/io/github/sskorol/utils/ReflectionUtils.java
// @SuppressWarnings("unchecked")
// public static <T> Class<T> castToObject(final Class<T> entityClass) {
//     return (Class<T>) (entityClass.isArray() ? entityClass.getComponentType() : entityClass);
// }


import com.google.gson.Gson;
import com.google.gson.JsonElement;
import lombok.AllArgsConstructor;
import lombok.Getter;
import one.util.streamex.StreamEx;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import static com.google.gson.JsonParser.parseReader;
import static io.github.sskorol.utils.ReflectionUtils.castToArray;
import static io.github.sskorol.utils.ReflectionUtils.castToObject;
import static io.vavr.API.*;
import static java.lang.String.format;
package io.github.sskorol.data;




@AllArgsConstructor
public class JsonReader<T> implements DataReader<T> {

    @Getter
    private final Class<T> entityClass;
    @Getter
    private final String path;

    public JsonReader(final Class<T> entityClass) {
        this(entityClass, "");
    }

    @SuppressWarnings("unchecked")
    public StreamEx<T> read() {
        var gson = new Gson();
        try (var streamReader = new InputStreamReader(getUrl().openStream(), StandardCharsets.UTF_8);
             var jsonReader = new com.google.gson.stream.JsonReader(streamReader)) {
            return StreamEx.of((T[]) Match(parseReader(jsonReader)).of(
                Case($(JsonElement::isJsonArray), j -> gson.fromJson(j, castToArray(entityClass))),
// Path: src/main/java/io/github/sskorol/utils/ReflectionUtils.java
// @SuppressWarnings("unchecked")
// public static <T> Class<T[]> castToArray(final Class<T> entityClass) {
//     return (Class<T[]>) (entityClass.isArray() ? entityClass : Array.newInstance(entityClass, 1).getClass());
// }
// 
// Path: src/main/java/io/github/sskorol/utils/ReflectionUtils.java
// @SuppressWarnings("unchecked")
// public static <T> Class<T> castToObject(final Class<T> entityClass) {
//     return (Class<T>) (entityClass.isArray() ? entityClass.getComponentType() : entityClass);
// }


// Path: src/main/java/io/github/sskorol/data/JsonReader.java
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import lombok.AllArgsConstructor;
import lombok.Getter;
import one.util.streamex.StreamEx;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import static com.google.gson.JsonParser.parseReader;
import static io.github.sskorol.utils.ReflectionUtils.castToArray;
import static io.github.sskorol.utils.ReflectionUtils.castToObject;
import static io.vavr.API.*;
import static java.lang.String.format;

package io.github.sskorol.data;




@AllArgsConstructor
public class JsonReader<T> implements DataReader<T> {

    @Getter
    private final Class<T> entityClass;
    @Getter
    private final String path;

    public JsonReader(final Class<T> entityClass) {
        this(entityClass, "");
    }

    @SuppressWarnings("unchecked")
    public StreamEx<T> read() {
        var gson = new Gson();
        try (var streamReader = new InputStreamReader(getUrl().openStream(), StandardCharsets.UTF_8);
             var jsonReader = new com.google.gson.stream.JsonReader(streamReader)) {
            return StreamEx.of((T[]) Match(parseReader(jsonReader)).of(
                Case($(JsonElement::isJsonArray), j -> gson.fromJson(j, castToArray(entityClass))),
                Case($(), j -> (T[]) new Object[] {gson.fromJson(j, castToObject(entityClass))})