package no.vegvesen.nvdbapi.client.gson;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

class Helper {
     static <T> List<T> parsePlainList(String file, Function<JsonObject, T> mapper) throws IOException {
         try(InputStream resource = Helper.class.getResourceAsStream("/jsonresponse/" + file)) {
             JsonElement response = new JsonParser().parse(new InputStreamReader(resource));
             JsonArray objekter = response.getAsJsonArray();
             return parseList(mapper, objekter);
         }
     }

    static <T> List<T> parseObjekterList(String file, Function<JsonObject, T> mapper) throws IOException {
        try(InputStream resource = Helper.class.getResourceAsStream("/jsonresponse/" + file)) {
            JsonElement response = new JsonParser().parse(new InputStreamReader(resource));
            JsonArray objekter = response.getAsJsonObject().get("objekter").getAsJsonArray();
            return parseList(mapper, objekter);
        }
    }


    private static <T> List<T> parseList(Function<JsonObject, T> mapper, JsonArray objekter) {
        return StreamSupport.stream(objekter.spliterator(), false)
            .map(JsonElement::getAsJsonObject)
            .map(mapper)
            .collect(Collectors.toList());
    }

    static <T> T parseObject(String file, Function<JsonObject, T> mapper) {
        InputStream resource = Helper.class.getResourceAsStream("/jsonresponse/" + file);
        JsonElement response = new JsonParser().parse(new InputStreamReader(resource));
        return mapper.apply(response.getAsJsonObject());
    }

    static <T> List<T> parseList(String file, Function<JsonObject, T> mapper) throws IOException {
        try(InputStream resource = Helper.class.getResourceAsStream("/jsonresponse/" + file)) {
            JsonElement response = new JsonParser().parse(new InputStreamReader(resource));
            return StreamSupport.stream(response.getAsJsonArray().spliterator(), false)
                    .map(JsonElement::getAsJsonObject)
                    .map(mapper)
                    .collect(Collectors.toList());

        }
    }
}

@@ -39,149 +39,8 @@
 n;%0A%0A
-import com.google.gson.JsonArray;%0Aimport com.google.gson.JsonElement;%0Aimport com.google.gson.JsonObject;%0Aimport com.google.gson.JsonParser;%0A%0A
 impo
@@ -59,24 +59,24 @@
 OException;%0A
+
 import java.
@@ -260,16 +260,157 @@
 pport;%0A%0A
+import com.google.gson.JsonArray;%0Aimport com.google.gson.JsonElement;%0Aimport com.google.gson.JsonObject;%0Aimport com.google.gson.JsonParser;%0A%0A
 class He
@@ -645,36 +645,32 @@
 ement response =
- new
  JsonParser().pa
@@ -660,32 +660,36 @@
 = JsonParser
-()
 .parse
+Reader
 (new InputSt
@@ -1069,36 +1069,32 @@
 ement response =
- new
  JsonParser().pa
@@ -1084,32 +1084,36 @@
 = JsonParser
-()
 .parse
+Reader
 (new InputSt
@@ -1767,36 +1767,32 @@
 ement response =
- new
  JsonParser().pa
@@ -1782,32 +1782,36 @@
 = JsonParser
-()
 .parse
+Reader
 (new InputSt
@@ -2130,12 +2130,8 @@
 se =
- new
  Jso
@@ -2141,16 +2141,20 @@
 rser
-()
 .parse
+Reader
 (new

Use static parser instead of deprecated constructor