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.
Update on Martin answer, Java SDK is released and available for public preview :- https://github.com/microsoftgraph/msgraph-sdk-java.
Im not aware of any Java SDK for Microsoft Graph. However, you can use jsonutil to generate your java objects which will reduce at least some work.
Edit: As mentioned by Pranay, a Java SDK is released, you should use this instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With