Search code examples
javaandroidjsonpostlinkedin-api

Converting my response to JsonObject format


I am fetching LinkedIn profile information upon logging in with your LinkedIn account and trying to send it to my server so I can store it. The response comes back to me in the form of an ApiResponse.

public void onApiSuccess(ApiResponse apiResponse) {
...
serverInteractionManager.sendLinkedInData(dummyJson, PreferenceManager.getPreference("eventId"), PreferenceManager.getPreference("personId"));
...    
}

The ApiResponse class has a getResponseDataAsJSON() method but that returns a JSONObject type as opposed to the JsonObject that I need.

public Future<JsonObject> sendLinkedInData(JsonObject jsonObject, String eventId, String personId) {
        try {
            return sendRequest("api/event/" + eventId + "/signup/" + personId, "").setJsonObjectBody(jsonObject).asJsonObject().setCallback(new FutureCallback<JsonObject>() {
                @Override
                public void onCompleted(Exception e, JsonObject result) {
                }
            });
        } catch (Exception e) {
            return null;
        }
}

Above is the method that sends a post request to my server, where I want to store the LinkedIn information I get after login.
Is there any way to convert between these two types? or convert a String to JsonObject somehow? (I can parse the ApiResponse to a String). I tried using Gson to not much success but I'm not very experienced with it. Cheers!


Solution

  • Was able to solve my problem using a JsonParser. Sorry for wasting your time!