Search in sources :

Example 6 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class JacksonCodecTest 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 JacksonEncoder().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 7 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class JacksonCodecTest method customEncoder.

@Test
public void customEncoder() throws Exception {
    JacksonEncoder encoder = new JacksonEncoder(Arrays.<Module>asList(new SimpleModule().addSerializer(Zone.class, new ZoneSerializer())));
    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 TypeReference<List<Zone>>() {
    }.getType(), template);
    assertThat(template).hasBody(//
    "" + "[ {\n" + "  \"name\" : \"DENOMINATOR.IO.\"\n" + "}, {\n" + "  \"name\" : \"DENOMINATOR.IO.\",\n" + "  \"id\" : \"ABCD\"\n" + "} ]");
}
Also used : RequestTemplate(feign.RequestTemplate) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 8 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class JacksonCodecTest 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 JacksonEncoder().encode(form, new TypeReference<Map<String, ?>>() {
    }.getType(), template);
    assertThat(template).hasBody(//
    "" + //
    "{\n" + //
    "  \"foo\" : 1,\n" + //
    "  \"bar\" : [ 2, 3 ]\n" + "}");
}
Also used : RequestTemplate(feign.RequestTemplate) TypeReference(com.fasterxml.jackson.core.type.TypeReference) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 9 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class JAXBCodecTest method encodesXmlWithCustomJAXBNoNamespaceSchemaLocation.

@Test
public void encodesXmlWithCustomJAXBNoNamespaceSchemaLocation() throws Exception {
    JAXBContextFactory jaxbContextFactory = new JAXBContextFactory.Builder().withMarshallerNoNamespaceSchemaLocation("http://apihost/schema.xsd").build();
    Encoder encoder = new JAXBEncoder(jaxbContextFactory);
    MockObject mock = new MockObject();
    mock.value = "Test";
    RequestTemplate template = new RequestTemplate();
    encoder.encode(mock, MockObject.class, template);
    assertThat(template).hasBody("<?xml version=\"1.0\" encoding=\"UTF-8\" " + "standalone=\"yes\"?><mockObject xsi:noNamespaceSchemaLocation=\"http://apihost/schema.xsd\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<value>Test</value></mockObject>");
}
Also used : Encoder(feign.codec.Encoder) RequestTemplate(feign.RequestTemplate) Test(org.junit.Test)

Example 10 with RequestTemplate

use of feign.RequestTemplate in project feign by OpenFeign.

the class JAXBCodecTest method encodesXmlWithCustomJAXBFormattedOutput.

@Test
public void encodesXmlWithCustomJAXBFormattedOutput() {
    JAXBContextFactory jaxbContextFactory = new JAXBContextFactory.Builder().withMarshallerFormattedOutput(true).build();
    Encoder encoder = new JAXBEncoder(jaxbContextFactory);
    MockObject mock = new MockObject();
    mock.value = "Test";
    RequestTemplate template = new RequestTemplate();
    encoder.encode(mock, MockObject.class, template);
    String NEWLINE = System.getProperty("line.separator");
    assertThat(template).hasBody(new StringBuilder().append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>").append(NEWLINE).append("<mockObject>").append(NEWLINE).append("    <value>Test</value>").append(NEWLINE).append("</mockObject>").append(NEWLINE).toString());
}
Also used : Encoder(feign.codec.Encoder) RequestTemplate(feign.RequestTemplate) 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