use of retrofit2.http.FieldMap in project retrofit by square.
the class RequestBuilderTest method formEncodedWithEncodedNameFieldParamMap.
@Test
public void formEncodedWithEncodedNameFieldParamMap() {
class Example {
//
@FormUrlEncoded
//
@POST("/foo")
Call<ResponseBody> method(@FieldMap(encoded = true) Map<String, Object> fieldMap) {
return null;
}
}
Map<String, Object> fieldMap = new LinkedHashMap<>();
fieldMap.put("k%20it", "k%20at");
fieldMap.put("pin%20g", "po%20ng");
Request request = buildRequest(Example.class, fieldMap);
assertBody(request.body(), "k%20it=k%20at&pin%20g=po%20ng");
}
use of retrofit2.http.FieldMap in project retrofit by square.
the class RequestBuilderTest method fieldMapSupportsSubclasses.
@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");
}
use of retrofit2.http.FieldMap in project retrofit by square.
the class RequestBuilderTest method formEncodedFieldMap.
@Test
public void formEncodedFieldMap() {
class Example {
//
@FormUrlEncoded
//
@POST("/foo")
Call<ResponseBody> method(@FieldMap Map<String, Object> fieldMap) {
return null;
}
}
Map<String, Object> fieldMap = new LinkedHashMap<>();
fieldMap.put("kit", "kat");
fieldMap.put("ping", "pong");
Request request = buildRequest(Example.class, fieldMap);
assertBody(request.body(), "kit=kat&ping=pong");
}
Aggregations