0

I am using Retrofit2 to call a rest endpoint which accepts a SQL query. When I tried testing with Postman this worked when I set Content-Type: application/sql and passed a raw string. Is there a way to pass a raw string as body using Retrofit2? The response is returned in json format. The below implementation seems to fail and I assume it is adding probably adding quotes to the front and end of the query string.

@Headers({ "Content-Type: application/sql" })
@POST(RestConstants.SQL_URL)
Call<AppResponse> query(@Body String query);



Retrofit client = new Retrofit.Builder()
        .baseUrl(service_host)
        .addConverterFactory(JacksonConverterFactory.create(jacksonObjMapper))
        .client(getHttpClientBuilder(username, password).build())
        .build();
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315
  • Does this answer your question? [How to POST raw whole JSON in the body of a Retrofit request?](https://stackoverflow.com/questions/21398598/how-to-post-raw-whole-json-in-the-body-of-a-retrofit-request) – GreyBeardedGeek Jul 12 '21 at 01:18
  • Sorry, doesn't seem to answer. In my case , I need to pass a string in the request with content type "application/sql" and deserialize that into another object in the response. I was able to figure a workaround by using "ScalarsConverterFactory.create())" as a converterFactory but still this can only return a String in the response and cannot deserialize this into an object. – Punter Vicky Jul 12 '21 at 03:08

0 Answers0