I am trying to access Microsoft Graph API using the following code in Java :-
String url_str = "https://graph.microsoft.com/v1.0/users/";
String access_token = getAccessToken();
url = new URL(url_str);
con = ( HttpURLConnection )url.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", access_token);
con.setRequestProperty("Accept","application/json");
con.connect();
br = new BufferedReader(new InputStreamReader( con.getInputStream() ));
String str = null;
String line;
while((line = br.readLine()) != null) {
str += line;
}
System.out.println(str);
} catch (Exception e) {
e.printStackTrace();
}
Currently I am getting JSON String which i will need to parse further. All I want to know is there any other way which will reduce the pain of deserialization or something more better.