Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

A Retrofit 2 converter to convert your request and response data to org.json.JSONObject

License

Notifications You must be signed in to change notification settings

sebastien-roch/retrofit2-jsonobject-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Retrofit2 JSONObject converter

A Retrofit 2 converter to convert your request and response data to org.json.JSONObject.

Compatibility

Tested with Retrofit 2.0.0-beta2

Usage

Register the converter:

OkHttpClient client = new OkHttpClient();
Retrofit restAdapter = new Retrofit.Builder()
        .baseUrl(endPoint)
        .client(client)
        .addConverterFactory(JsonConverterFactory.create())
        .build();

api = restAdapter.create(PdApiInterface.class);

In your API interface file:

@POST("/v2/package")
    Call<JSONObject> subscribePackage(@Body JSONObject data);

@GET("/v2/account/{id}")
    Call<JSONObject> getAccount(@Path("id") int id);

Then in your code:

Call c = api.getAccount(getApiManager().getAccountId());
c.enqueue(new Callback<JSONObject>() {
    @Override
    public void onResponse(Response<JSONObject> response, Retrofit retrofit) {
        if (response.isSuccess()) {
            // response.body() is a JSONObject
            onDataReceived(response.body());
        }
    }

    @Override
    public void onFailure(Throwable t) {

    }
});

About

A Retrofit 2 converter to convert your request and response data to org.json.JSONObject

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages