Java Code Examples for retrofit2.http.FieldMap

The following are top voted examples for showing how to use retrofit2.http.FieldMap. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test public void fieldMapRejectsNull() {
  class Example {
    @FormUrlEncoded //
    @POST("/") //
    Call<ResponseBody> method(@FieldMap Map<String, Object> a) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage("Field map was null.");
  }
}
 
Example 2
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test public void fieldMapRejectsNullKeys() {
  class Example {
    @FormUrlEncoded //
    @POST("/") //
    Call<ResponseBody> method(@FieldMap Map<String, Object> a) {
      return null;
    }
  }

  Map<String, Object> fieldMap = new LinkedHashMap<>();
  fieldMap.put("kit", "kat");
  fieldMap.put(null, "pong");

  try {
    buildRequest(Example.class, fieldMap);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage("Field map contained null key.");
  }
}
 
Example 3
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test public void fieldMapRejectsNullValues() {
  class Example {
    @FormUrlEncoded //
    @POST("/") //
    Call<ResponseBody> method(@FieldMap Map<String, Object> a) {
      return null;
    }
  }

  Map<String, Object> fieldMap = new LinkedHashMap<>();
  fieldMap.put("kit", "kat");
  fieldMap.put("foo", null);

  try {
    buildRequest(Example.class, fieldMap);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage("Field map contained null value for key 'foo'.");
  }
}
 
Example 4
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test public void fieldMapMustBeAMap() {
  class Example {
    @FormUrlEncoded //
    @POST("/") //
    Call<ResponseBody> method(@FieldMap List<String> a) {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@FieldMap parameter type must be Map. (parameter #1)\n    for method Example.method");
  }
}
 
Example 5
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test public void fieldMapSupportsSubclasses() throws IOException {
  class Foo extends HashMap<String, String> {
  }

  class Example {
    @FormUrlEncoded //
    @POST("/") //
    Call<ResponseBody> method(@FieldMap Foo a) {
      return null;
    }
  }

  Foo foo = new Foo();
  foo.put("hello", "world");

  Request request = buildRequest(Example.class, foo);
  Buffer buffer = new Buffer();
  request.body().writeTo(buffer);
  assertThat(buffer.readUtf8()).isEqualTo("hello=world");
}
 
Example 6
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test public void fieldMapRejectsNull() {
  class Example {
    @FormUrlEncoded //
    @POST("/") //
    Call<ResponseBody> method(@FieldMap Map<String, Object> a) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage("Field map was null.");
  }
}
 
Example 7
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test public void fieldMapRejectsNullKeys() {
  class Example {
    @FormUrlEncoded //
    @POST("/") //
    Call<ResponseBody> method(@FieldMap Map<String, Object> a) {
      return null;
    }
  }

  Map<String, Object> fieldMap = new LinkedHashMap<>();
  fieldMap.put("kit", "kat");
  fieldMap.put(null, "pong");

  try {
    buildRequest(Example.class, fieldMap);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage("Field map contained null key.");
  }
}
 
Example 8
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test public void fieldMapRejectsNullValues() {
  class Example {
    @FormUrlEncoded //
    @POST("/") //
    Call<ResponseBody> method(@FieldMap Map<String, Object> a) {
      return null;
    }
  }

  Map<String, Object> fieldMap = new LinkedHashMap<>();
  fieldMap.put("kit", "kat");
  fieldMap.put("foo", null);

  try {
    buildRequest(Example.class, fieldMap);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage("Field map contained null value for key 'foo'.");
  }
}
 
Example 9
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test public void fieldMapMustBeAMap() {
  class Example {
    @FormUrlEncoded //
    @POST("/") //
    Call<ResponseBody> method(@FieldMap List<String> a) {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@FieldMap parameter type must be Map. (parameter #1)\n    for method Example.method");
  }
}
 
Example 10
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test public void fieldMapSupportsSubclasses() throws IOException {
  class Foo extends HashMap<String, String> {
  }

  class Example {
    @FormUrlEncoded //
    @POST("/") //
    Call<ResponseBody> method(@FieldMap Foo a) {
      return null;
    }
  }

  Foo foo = new Foo();
  foo.put("hello", "world");

  Request request = buildRequest(Example.class, foo);
  Buffer buffer = new Buffer();
  request.body().writeTo(buffer);
  assertThat(buffer.readUtf8()).isEqualTo("hello=world");
}
 
Example 11
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 6 votes vote down vote up
@Test public void fieldParamMapsConvertedToNullShouldError() throws Exception {
  class Example {
    @FormUrlEncoded
    @POST("/query") Call<ResponseBody> queryPath(@FieldMap Map<String, String> a) {
      return null;
    }
  }

  Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
      .baseUrl("http://example.com")
      .addConverterFactory(new NullObjectConverterFactory());

  Map<String, String> queryMap = Collections.singletonMap("kit", "kat");

  try {
    buildRequest(Example.class, retrofitBuilder, queryMap);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessageContaining(
        "Field map value 'kat' converted to null by retrofit2.helpers.NullObjectConverterFactory$1 for key 'kit'.");
  }
}
 
Example 12
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 5 votes vote down vote up
@Test public void implicitFormEncodingByFieldMapForbidden() {
  class Example {
    @POST("/") //
    Call<ResponseBody> method(@FieldMap Map<String, String> a) {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@FieldMap parameters can only be used with form encoding. (parameter #1)\n    for method Example.method");
  }
}
 
Example 13
Project: GitHub   File: RequestBuilderTest.java   Source Code and License 5 votes vote down vote up
@Test public void implicitFormEncodingByFieldMapForbidden() {
  class Example {
    @POST("/") //
    Call<ResponseBody> method(@FieldMap Map<String, String> a) {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@FieldMap parameters can only be used with form encoding. (parameter #1)\n    for method Example.method");
  }
}
 
Example 14
Project: Rxjava2.0Demo   File: LoginApi.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@POST(Constant.URL_LOGIN)
Observable<ResponseBody> login(@FieldMap Map<String, String> map);
 
Example 15
Project: Rxjava2.0Demo   File: LoginApi.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
Observable<ResponseBody> getToken(@Url String url, @FieldMap Map<String, String> map);
 
Example 16
Project: Rxjava2.0Demo   File: LoginApi.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
Observable<ResponseBody> getUserInfo(@Url String url, @FieldMap Map<String, String> map);
 
Example 17
Project: SuperHttp   File: ApiService.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@POST()
Observable<ResponseBody> post(@Url() String url, @FieldMap Map<String, String> maps);
 
Example 18
Project: RX_Demo   File: GankApi.java   Source Code and License 4 votes vote down vote up
/**
 * 登录
 */
@FormUrlEncoded
@POST(BaseApi.Url.URL_LOGIN)
Observable<JSONObject> login(@FieldMap Map<String, String> map);
 
Example 19
Project: RX_Demo   File: GankApi.java   Source Code and License 4 votes vote down vote up
/**
 * 登出
 */
@FormUrlEncoded
@POST(BaseApi.Url.URL_API_LOGIN)
Observable<Model1<UserModel>> logout(@FieldMap Map<String, String> map);
 
Example 20
Project: RX_Demo   File: PassportApi.java   Source Code and License 4 votes vote down vote up
/**
 * 注册
 */
@FormUrlEncoded
@POST(BaseApi.Url.URL_REGISTER)
Observable<JSONObject> register(@FieldMap Map<String, String> map);
 
Example 21
Project: RX_Demo   File: PassportApi.java   Source Code and License 4 votes vote down vote up
/**
 * 注册
 */
@FormUrlEncoded
@POST(BaseApi.Url.URL_GET_NICK_NAME)
Observable<UserModel> getNickname(@FieldMap Map<String, String> map);
 
Example 22
Project: AppFirCloud   File: PassportApi.java   Source Code and License 4 votes vote down vote up
/**
 * 登录
 */
@FormUrlEncoded
@POST(BaseApi.Url.URL_REGISTER)
Observable<JSONObject> login(@FieldMap Map<String, String> map);
 
Example 23
Project: OAuth-2.0-Cookbook   File: OAuth2API.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@POST("oauth/token")
Call<AccessToken> requestToken(@FieldMap Map<String, String> tokenRequest);
 
Example 24
Project: OAuth-2.0-Cookbook   File: OAuth2API.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@POST("oauth/token")
Call<AccessToken> requestToken(@FieldMap Map<String, String> tokenRequest);
 
Example 25
Project: OAuth-2.0-Cookbook   File: OAuth2API.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@POST("oauth/token")
Call<AccessToken> requestToken(@FieldMap Map<String, String> tokenRequest);
 
Example 26
Project: SuperHttp   File: ApiService.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@PATCH()
Observable<ResponseBody> patch(@Url() String url, @FieldMap Map<String, String> maps);
 
Example 27
Project: XSnow   File: ApiService.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@POST()
Observable<ResponseBody> post(@Url() String url, @FieldMap Map<String, String> maps);
 
Example 28
Project: XSnow   File: ApiService.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@POST()
Observable<ResponseBody> postForm(@Url() String url, @FieldMap Map<String, Object> maps);
 
Example 29
Project: XSnow   File: ApiService.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@PUT()
Observable<ResponseBody> put(@Url() String url, @FieldMap Map<String, String> maps);
 
Example 30
Project: XSnow   File: ApiService.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@PATCH()
Observable<ResponseBody> patch(@Url() String url, @FieldMap Map<String, String> maps);
 
Example 31
Project: XSnow   File: ApiService.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@DELETE()
Observable<ResponseBody> delete(@Url() String url, @FieldMap Map<String, String> maps);
 
Example 32
Project: AndroidBasicLibs   File: ApiService.java   Source Code and License 4 votes vote down vote up
@POST()
@FormUrlEncoded
Observable<ResponseBody> post(@Url() String url, @FieldMap Map<String, String> maps);
 
Example 33
Project: AndroidBasicLibs   File: ApiService.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@POST()
Observable<ResponseBody> postForm(@Url() String url, @FieldMap Map<String, Object> maps);
 
Example 34
Project: JD-Test   File: BaseApiService.java   Source Code and License 4 votes vote down vote up
@POST()
@FormUrlEncoded
Flowable<ResponseBody> executePost(
        @Url() String url,
        @FieldMap Map<String, Object> maps);
 
Example 35
Project: JD-Test   File: BaseApiService.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@POST()
Flowable<ResponseBody> postForm(
        @Url() String url,
        @FieldMap Map<String, Object> maps);
 
Example 36
Project: RxEasyHttp   File: ApiService.java   Source Code and License 4 votes vote down vote up
@POST()
@FormUrlEncoded
Observable<ResponseBody> post(@Url String url, @FieldMap Map<String, String> maps);
 
Example 37
Project: RxEasyHttp   File: LoginService.java   Source Code and License 4 votes vote down vote up
@POST("{path}")
@FormUrlEncoded
Observable<ApiResult<AuthModel>> login(@Path("path") String path, @FieldMap Map<String, String> map);
 
Example 38
Project: GxIconDIY   File: NanoServerService.java   Source Code and License 4 votes vote down vote up
/**
 * { "status": 0, "msg": "success", "result": 5 }
 */
@FormUrlEncoded
@POST("req/{iconpack}")
Call<ResResBean<Integer>> reqRedraw(@Path("iconpack") String iconPack,
                                    @FieldMap Map<String, String> fields);
 
Example 39
Project: GxIconAndroid   File: NanoServerService.java   Source Code and License 4 votes vote down vote up
/**
 * { "status": 0, "msg": "success", "result": 5 }
 */
@FormUrlEncoded
@POST("req/{iconpack}")
Call<ResResBean<Integer>> reqRedraw(@Path("iconpack") String iconPack,
                                    @FieldMap Map<String, String> fields);
 
Example 40
Project: FastEc   File: RestService.java   Source Code and License 4 votes vote down vote up
@FormUrlEncoded
@POST
Call<String> post(@Url String url, @FieldMap Map<String, Object> params);