Question


I'm following this guide - https://github.com/excilys/androidannotations/wiki/Rest%20API and I am trying skip JSON<->POJO conversion and work on pure JSONObject (or gson's JsonObject). What should I write as an server's answer?

@Rest("url")
public interface JsonRest
{
    @Get("/getjson")
    JSONObject getTime();
        // or... ? 
    @Get("/getjson")
    ResponseEntity<JSONObject> getTime();
        // or... ? 
    @Get("/getjson")
    JsonObject getTime();  
}

In all cases I am getting "{}" as a response, but it's contains correct data after POJO conversion. Which HTTPMessageConverter should I provide?

Thanks for any help.

Was it helpful?

Solution

Simply add GsonHttpMessageConverter to RestTemplate and try this:

@Get("/getjson")
JsonElement getSomething();

OTHER TIPS

I don't think this is supported by Spring Android RestTemplate by default. You should probably provide your own provider.

You could look at how GsonHttpMessageConverter is implemented here and then implement your own solution based on that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top