How to read a json file from GCP bucket using java

850 views Asked by At

I am trying to read a json file and map to Gson object on fly, tired reading using FileReader which is not working, also tried multiple ways but no luck.. can someone help me in reading from gcp bucket

public static Response[] getJsonData() {

        try {

            JsonReader reader = new JsonReader(new FileReader("gs://01test_dataflow/data_schema.json"));
            Response[] response = new Gson().fromJson(reader, Response[].class);

            return response;

        } catch (NullPointerException e) {

            e.printStackTrace();
            return null;

        } catch (FileNotFoundException e) {

            e.printStackTrace();
            return null;

        } catch (Exception e) {

            e.printStackTrace();
            return null;
        }
    }
0

There are 0 answers