use of feign.codec.EncodeException in project feign by OpenFeign.
the class JacksonJaxbJsonEncoder method encode.
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
jacksonJaxbJsonProvider.writeTo(object, bodyType.getClass(), null, null, APPLICATION_JSON_TYPE, null, outputStream);
template.body(outputStream.toByteArray(), Charset.defaultCharset());
} catch (IOException e) {
throw new EncodeException(e.getMessage(), e);
}
}
use of feign.codec.EncodeException in project feign by OpenFeign.
the class JacksonEncoder method encode.
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
try {
JavaType javaType = mapper.getTypeFactory().constructType(bodyType);
template.body(mapper.writerFor(javaType).writeValueAsString(object));
} catch (JsonProcessingException e) {
throw new EncodeException(e.getMessage(), e);
}
}
use of feign.codec.EncodeException in project feign by OpenFeign.
the class JAXBEncoder method encode.
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
if (!(bodyType instanceof Class)) {
throw new UnsupportedOperationException("JAXB only supports encoding raw types. Found " + bodyType);
}
try {
Marshaller marshaller = jaxbContextFactory.createMarshaller((Class) bodyType);
StringWriter stringWriter = new StringWriter();
marshaller.marshal(object, stringWriter);
template.body(stringWriter.toString());
} catch (JAXBException e) {
throw new EncodeException(e.toString(), e);
}
}
Aggregations