Urkman
Urkman

Reputation: 1318

AndroidAnnotations, REST and custom response

I'm using AndroidAnnotations in my project. This works fine so far...

But now I try to access a given Webservice with a custom response like this:

{ 
    success: true,
    total: 100,
    items: [],
}

This response format is the same for every GET request. The items property holds the response objects I'm interested in and the items contains different object type(like user, product etc)

I'm using "MappingJackson2HttpMessageConverter"...

How can I access them?

Thanks, Stefan

Upvotes: 0

Views: 60

Answers (1)

WonderCsabo
WonderCsabo

Reputation: 12207

You have to create the response class, which can be deserialized from the JSON response:

public class CustomResponse {
  boolean success;
  int total;
  List<Integer> items;
}

This is just an example, because it is ambigous from your JSON snippet, what exact types you are using. Then you can use this response class in your REST client:

@Get("/getsomething")
public CustomResponse getSomething();

It is not necessary to use MappingJackson2HttpMessageConverter, you could use any converter which can convert your JSON response (like a GSON converter).

Upvotes: 1

Related Questions