Vladislav Aniskin Vladislav Aniskin - 7 months ago 585
Android Question

Post raw json in body retrofit2

I want post json request like that

{"jsonrpc": "2.0", "method": "testApi", "params": {
"message": "abc"
, "id": 1}

I read posts:

How to POST raw whole JSON in the body of a Retrofit request?

but i can'not found class TypedInput, TypedByteArray, TypedString in my retrofit2 package. Where is?


To POST a body in Retrofit, you create an object that represents this body, a class that includes String jsonrpc, String method, etc. Then, pass this object to the method that you define in your service interface and has a param with @Body annotation.

Here is an example for POST body object:

public class PostBody{

   String jsonprc;
   String method;
   Param param;

   public PostBody(...){


   class Param{