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" + "}");
}
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" + "} ]");
}
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" + "}");
}
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>");
}
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());
}
Aggregations