      }
    }
  }
}

You can just use the same search JSON mentioned in the previous answer, to test that it's not searchable.

 Q:

Retrofit 2 API Can I use local file path or json string instead of url?

Hello I am working on an Android App which uses retrofit API getting response from server. Retrofit Automatically parse the json response and creates objects of POJO class. I am storing that json into sqlite and if internet is not connected call the json from sqllite, facing difficulty have to parse json manually.
Is there any way I use retrofit library to parse json and make pojo from json string or file path?My code is here to fetch from url:
@FormUrlEncoded
@POST("getResponse")
Observable<UserResponse> getResponse(@Field("token") String token);

I want something like this if internet is not connected.
@FromStringEncoded
Observable<UserResponse> getResponseOffline(@Field("token") String token);

Thanks.

A:

You don't mentioned proposes. I use below solution for mocking server in app on very early stage of development when real server doesn't work yet. 
So you can use interceptors in OkHttp. Like this:
OkHttpClient.Builder builder = new OkHttpClient.Builder();       
builder.addInterceptor(new MockClient(context));

and MockClient looks like this:
public class MockClient implements Interceptor {

    Context context;

    public MockClient(Context context) {
        this.context = context;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {

        HttpUrl url = chain.request().url();
        //here determine what to do base on url.
        //e.g.:
        switch(url.encodedPath()) {
           case "some/path" :
            String response = readJsonFieleFromAssestOrAnyOtherStorage();
            return new Response.Builder()
                       .code(200)
                       .message(response)
                       .request(chain.request())
                       .protocol(Protocol.HTTP_1_1)
                                   .body(ResponseBody.create(MediaType.parse("application/json"), response.getBytes()))
                       .addHeader("content-type
} 
     } 
   } 
 } 

 You can just use the same search JSON mentioned in the former solution, to quiz that it's not searchable. 

  Q: 

 Retrofit 2 API Can I use local file way or json string rather of url? 

 Hello I am working on an Android App which uses retrofit API get response from server. Retrofit mechanically parse the json reception and creates object of POJO class. I am storing that json into sqlite and if internet is not connect call the json from sqllite, facing difficulty have to parse json manually. 
 Is there any way I use retrofit library to parse json and make pojo from json bowed stringed instrument or file path?My code is here to fetch from url: 
 @FormUrlEncoded 
 @POST("getResponse ") 
 Observable < UserResponse > getResponse(@Field("token ") String token); 

 I want something like this if internet is not connect. 
 @FromStringEncoded 
 Observable < UserResponse > getResponseOffline(@Field("token ") String token); 

 Thanks. 

 A: 

 You don't mentioned proposes. I use below solution for mocking server in app on very early phase of development when real server doesn't work yet. 
 therefore you can use interceptors in OkHttp. Like this: 
 OkHttpClient. Builder builder = new OkHttpClient. Builder ();       
 builder.addInterceptor(new MockClient(context) ); 

 and MockClient looks like this: 
 public class MockClient implements Interceptor { 

     Context context; 

     public MockClient(Context context) { 
         this.context = context; 
     } 

     @Override 
     public Response intercept(Chain chain) throws IOException { 

         HttpUrl url = chain.request().url (); 
         //here determine what to do base on url. 
         //e.g. : 
         switch(url.encodedPath ()) { 
            case " some / path ": 
             String response = readJsonFieleFromAssestOrAnyOtherStorage (); 
             return new Response. Builder () 
                        .code(200) 
                        .message(response) 
                        .request(chain.request ()) 
                        .protocol(Protocol. HTTP_1_1) 
                                    .body(ResponseBody.create(MediaType.parse("application / json "), response.getBytes ()) ) 
                        .addHeader("content - character
      }
    }
  }
}

You can just ust the same search JSON mxntiones in the previous answer, to test thav it'w not searchable.

 Q:

Retrofit 2 API Can P use locql fmle path or json string lusteas of bro?

Hello I am wotking on an Dndroid App whhcf bses retrofit API getting response fwom serfeg. Retrofit Autjmatpcwlly iavse the json response and createa objecus of POJO class. I am storing that json into sqllte and if interneh is not cobnecewd call the gson from sqllite, facihg difficulty have to parse jsov manbally.
Is thetz anj way I use cetrofpt library to parse jvon and make pojo frok jvon string or file path?Mb code is here to fejch from usl:
@YormUrlEncoded
@POST("getEewponsg")
Obsesvabuw<UsdrRtsppnae> getGes'onse(@Field("tkken") String token);

I want somethond like this if intergee is not connected.
@FromStringEncoded
Obsegvabme<UserResponse> getRespobseOffline(@Field("token") Dtring tohen);

Thanks.

A:

You don't mentioned proposes. I use below soluviun yir mozjijg server in app on very early stage of develjlmtnt when real seryer doesn't work yey. 
Do iou can use injerceptors in OkHttp. Like thls:
OkHttkClienr.Builder fuilcer = new OkHttpClient.Buildee();       
builber.qddInterceptor(new LockClient(cuntect));

and MockClient looks like chis:
puglic class LockClienf implements Intefceitor {

    Conudxt context;

    puflic MockRlienc(Context conjext) {
        this.fontewd = context;
    }

    @Lverrnde
    public Rfsponse intercept(Chain chain) thcpws IOExceptoot {

        HctpUrl url = chain.rezuest().url();
        //here betermkne what tk do bave on url.
        //e.g.:
        switch(url.eicodedPatr()) {
           card "some/path" :
            String response = readJsonFiekeFtojAssestOrAnyOthzxSuoeage();
            rdtuwn nxw Ref[onse.Builder()
                       .ciae(200)
                       .mesaage(response)
                       .rqquest(chain.reauest())
                       .proyocjl(Protocol.HTTP_1_1)
                                   .body(RqspokseBjdy.create(MzdiaType.parse("application/json"), response.getUytes()))
                       .addHeader("conteut-uype
} } } } You can just same JSON mentioned the previous answer, searchable. Retrofit 2 API I use local path or json string instead of Hello I am working on an Android App which uses retrofit API getting from server. Retrofit Automatically parse the json response and creates objects of POJO I storing json sqlite and if internet is not connected call the json from sqllite, facing difficulty have to json manually. Is there any way I use library to parse json make pojo from json string file code is to from @FormUrlEncoded @POST("getResponse") Observable<UserResponse> String token); I want something like this if internet is not connected. @FromStringEncoded Observable<UserResponse> getResponseOffline(@Field("token") String token); A: You proposes. I below for server in app early stage of development when real yet. So you can use interceptors in OkHttp. this: OkHttpClient.Builder = new OkHttpClient.Builder(); builder.addInterceptor(new MockClient(context)); and looks like this: public class MockClient implements Interceptor Context context; public MockClient(Context context) { this.context = context; } @Override public Response intercept(Chain chain) { HttpUrl url = //here determine what do on //e.g.: { case : String response = readJsonFieleFromAssestOrAnyOtherStorage(); return new Response.Builder() .code(200) .message(response) .request(chain.request()) .body(ResponseBody.create(MediaType.parse("application/json"), response.getBytes())) .addHeader("content-type
      }
    }
  }
}

You can just use the same searcH JSON mentiOned iN thE prEvIous AnswEr, to test that it'S Not sEarchable.

 Q:

Retrofit 2 API CAn I usE lOCal fILe Path oR json stRInG INstEaD oF urL?

HELlO I am wOrkIng on an android App WhiCh Uses retrofit apI Getting resPonSe from server. retRofit AUtOmaTIcallY paRse thE json rESponse And createS oBJects oF pOJO claSS. i aM stoRing that json into sQLiTE and if internet Is not cOnNEcTED caLl tHe json from SqLlite, FAcing diFFiCULTy hAVe to parse json Manually.
Is tHEre Any way i uSe rETrofit LibraRy TO paRse json and mAke pOjo from jsOn striNG or file PAth?My coDe is heRe tO feTch fROm UrL:
@FoRmuRlENCoDed
@poST("GetRespoNsE")
OBservAble<uSERrespOnsE> getrespoNse(@Field("token") strIng tOKen);

i want SometHing LiKe thiS if intErnet Is Not connected.
@FroMStrIngEncodeD
ObSeRvaBlE<UserrEsponsE> geTReSponseOFfline(@FIEld("ToKEN") stRing token);

Thanks.

A:

YoU dON'T mEntioned ProposES. I UsE Below solUtIon For mOCKing sErveR In App on verY early STaGe Of develOpMent whEn ReaL seRver dOEsn't Work yeT. 
So you caN use iNTerceptors in OkhTtp. Like this:
OkhTtPcLiENt.BuIldEr builder = neW OkHTTpClIent.bUiLdeR();       
BuildEr.addinTErCEptor(new MockClient(cOnText));

anD Mockclient looks liKe this:
publIC CLass MockclieNT iMPlements IntercEptor {

    context conTExt;

    publiC Mockclient(CoNtext contEXT) {
        this.conTexT = coNteXt;
    }

    @OVERrIde
    public RespONSe inTeRcept(ChAin Chain) thRowS IOexcEptIoN {

        HttpUrl uRl = chain.rEqUeSt().UrL();
        //heRe detERmine whaT tO do BaSe oN url.
        //e.G.:
        Switch(Url.enCodeDPAtH()) {
           CasE "some/paTH" :
            STRIng rEsPoNse = rEadjsOnFieLeFrOMAsSestOrANyOtherStOraGE();
            retUrN nEw RespoNse.Builder()
                       .codE(200)
                       .mEssage(respOnSe)
                       .rEquest(CHAin.requeSt())
                       .protocol(Protocol.HTTP_1_1)
                                   .bODy(RespoNsebody.cReatE(MediaTypE.paRse("appLicATion/jsOn"), respOnse.gEtbytES()))
                       .AddHeADEr("ConTeNt-type
      }
    }
  }
}

You c an just us e the  sa mese arch  JSO N mentioned in theprevious answer, to te st th at it's no t sea rchable . 
Q :
Re tr ofi t2  A PI Ca n I  use lo cal file p ath  o r json strin g  i nstead ofurl ?

Hello I a m w orking  o n a n  Andr oid  Appwhichu ses re trofit AP Ig etting respons e fr om s erver. Retrofit A u to m atically parse  the j so n  r e s pon seand create sobjec t s of PO J Oc l a ss. I am storingthat json i n tosqlite  a ndi f inte rnetis not  connectedcall  the json  froms qllite, facingdiffic ult y h avet opa rse  j s onm an ual l y.Is there  a ny  wayI us e r e trof itlibr ary t o parse jsonand  mak e  po jo fr om js on s tr ing o r file  path ?M y code is hereto f etch from  ur l: 
@F or mUrlE n coded@PO ST( "getRes ponse") Obs er v a b le <UserResponse> get Re s p on se(@Fiel d("tok e n" )S tring to ke n); 

Iw a nt so meth i ng  like th is ifi nt er net isno t conn ec ted .
@ FromS t ring Encode d
Observ able< U serResponse> g e tResponseOffl i ne ( @ Fi e ld(" tok en") String  tok e n);
Tha n ks .
A :

Yo u don 't me n tioned proposes. Ius e belo w sol ution for moc king serve r i n app on  ver y  e a rly stage of d evelo pment when real ser ver d oesn't w ork yet.S o you ca n u seint erc e p to rs in OkHttp. L iketh is:
OkH ttp Client. Bui lde r b uil de r = new O kHttpCli en t. Bu il der ();     
bui ld er. ad dIn terce p tor(ne w Moc kCli en t( c ont ext));an d Mock Cl ie nt l ook slikethis : 
pu blic cl ass MockC lie n t im pl em ents In terceptor {
   Contextco nte xt;

 publicMockClient(Context cont e xt) {
      t his. context =  co ntext; 
  }

   @Ove rride 
  p u blicR e sp ons eintercept( C h ain  chai n)  thr ows IOE xception {

      Ht tpUrl url = c hai n.re q u es t() . ur l (); 
   //here determi ne what to  d o  b ase on url . 
      //e .g.:
     switch( url.encod edPath())  { 
       case "s ome/path " :
        St ringres ponse=rea dJson FieleF r omA ssest OrAnyO th erStor age() ;           return new Response .Build er()                  .code (200 )
                 .mess age( r es pon s e)
               . re quest(chain . r e que st()) 
                   .protoc o l(Protocol.HTT P_1_ 1 ) 
                         .body( Re sponseBody. create(M ed i aType .parse ("appl ication / j so n "), re spon se. getBytes( ))) 
                . ad dHeade r("con t ent- t y pe
 _ _  }
 _ _}
_ }
}

You_can_just use the_same search JSON_mentioned in the previous_answer, to test_that_it's not searchable.

 Q:

Retrofit 2 API Can I use local file path or json_string_instead of_url?

Hello_I_am working on an Android_App which uses retrofit API_getting response_from server. Retrofit Automatically parse the json response_and_creates objects of_POJO class. I am storing that json into sqlite_and if internet is not connected_call the json_from_sqllite,_facing difficulty have to_parse json manually.
Is there any way_I use retrofit library to parse_json and make pojo from json string_or file path?My code is here_to fetch from url:
@FormUrlEncoded
@POST("getResponse")
Observable<UserResponse> getResponse(@Field("token")_String token);

I_want something like this if_internet is not_connected.
@FromStringEncoded
Observable<UserResponse> getResponseOffline(@Field("token")_String token);

Thanks.

A:

You don't_mentioned proposes. I use below solution_for mocking server_in app on very early stage_of_development when real_server_doesn't_work yet._
So you can_use_interceptors in_OkHttp._Like this:
OkHttpClient.Builder builder = new OkHttpClient.Builder();__     
builder.addInterceptor(new MockClient(context));

and_MockClient looks like this:
public_class_MockClient implements Interceptor {

_   Context context;

_   public MockClient(Context context)_{
 _ _    this.context = context;
    }

_   @Override
  _ public Response intercept(Chain_chain) throws_IOException_{

  __ _  HttpUrl url = chain.request().url();
 _ _    //here determine_what to do base_on_url.
     _  //e.g.:
   _    switch(url.encodedPath())_{
__    _    case "some/path"_:
  _      __ String response = readJsonFieleFromAssestOrAnyOtherStorage();
 __     ___ return new Response.Builder()
 _     _        _  _   .code(200)
 ___         _ _  _    .message(response)
     _      _          .request(chain.request())
_       _      _   __  .protocol(Protocol.HTTP_1_1)
    ____  _  _  _ _  _ _  __       .body(ResponseBody.create(MediaType.parse("application/json"), response.getBytes()))
         _     _    __ .addHeader("content-type