Search in sources :

Example 1 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class JacksonJaxbCodecTest method encodeTest.

@Test
public void encodeTest() {
    JacksonJaxbJsonEncoder encoder = new JacksonJaxbJsonEncoder();
    RequestTemplate template = new RequestTemplate();
    encoder.encode(new MockObject("Test"), MockObject.class, template);
    assertThat(template).hasBody("{\"value\":\"Test\"}");
}
Also used : RequestTemplate(feign.RequestTemplate) Test(org.junit.Test)

Example 2 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class GsonCodecTest method customEncoder.

@Test
public void customEncoder() throws Exception {
    GsonEncoder encoder = new GsonEncoder(Arrays.<TypeAdapter<?>>asList(upperZone));
    List<Zone> zones = new LinkedList<Zone>();
    zones.add(new Zone("denominator.io."));
    zones.add(new Zone("denominator.io.", "abcd"));
    RequestTemplate template = new RequestTemplate();
    encoder.encode(zones, new TypeToken<List<Zone>>() {
    }.getType(), template);
    assertThat(template).hasBody(//
    "" + //
    "[\n" + //
    "  {\n" + //
    "    \"name\": \"DENOMINATOR.IO.\"\n" + //
    "  },\n" + //
    "  {\n" + //
    "    \"name\": \"DENOMINATOR.IO.\",\n" + //
    "    \"id\": \"ABCD\"\n" + //
    "  }\n" + "]");
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) RequestTemplate(feign.RequestTemplate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 3 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class GsonCodecTest method encodesMapObjectNumericalValuesAsInteger.

@Test
public void encodesMapObjectNumericalValuesAsInteger() throws Exception {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    map.put("foo", 1);
    RequestTemplate template = new RequestTemplate();
    new GsonEncoder().encode(map, map.getClass(), template);
    assertThat(template).hasBody(//
    "" + //
    "{\n" + //
    "  \"foo\": 1\n" + "}");
}
Also used : RequestTemplate(feign.RequestTemplate) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 4 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class GsonCodecTest method encodesFormParams.

@Test
public void encodesFormParams() throws Exception {
    Map<String, Object> form = new LinkedHashMap<String, Object>();
    form.put("foo", 1);
    form.put("bar", Arrays.asList(2, 3));
    RequestTemplate template = new RequestTemplate();
    new GsonEncoder().encode(form, new TypeToken<Map<String, ?>>() {
    }.getType(), template);
    assertThat(template).hasBody(// 
    "" + //
    "{\n" + //
    "  \"foo\": 1,\n" + //
    "  \"bar\": [\n" + //
    "    2,\n" + //
    "    3\n" + //
    "  ]\n" + "}");
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) RequestTemplate(feign.RequestTemplate) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 5 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class DefaultEncoderTest method testRefusesToEncodeOtherTypes.

@Test
public void testRefusesToEncodeOtherTypes() throws Exception {
    thrown.expect(EncodeException.class);
    thrown.expectMessage("is not a type supported by this encoder.");
    encoder.encode(new Date(), Date.class, new RequestTemplate());
}
Also used : RequestTemplate(feign.RequestTemplate) Date(java.util.Date) Test(org.junit.Test)

Aggregations

RequestTemplate (feign.RequestTemplate)18 Test (org.junit.Test)18 Encoder (feign.codec.Encoder)4 LinkedHashMap (java.util.LinkedHashMap)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 TypeToken (com.google.gson.reflect.TypeToken)2 LinkedList (java.util.LinkedList)2 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 Type (java.lang.reflect.Type)1 Date (java.util.Date)1 Map (java.util.Map)1 XmlAccessType (javax.xml.bind.annotation.XmlAccessType)1 XmlAccessorType (javax.xml.bind.annotation.XmlAccessorType)1