MCPcopy Index your code
hub / github.com/OpenFeign/feign / JAXBEncoder

Class JAXBEncoder

jaxb/src/main/java/feign/jaxb/JAXBEncoder.java:45–68  ·  view source on GitHub ↗

Encodes requests using JAXB. Basic example with with Feign.Builder: JAXBContextFactory jaxbFactory = new JAXBContextFactory.Builder() .withMarshallerJAXBEncoding("UTF-8") .withMarshallerSchemaLocation("http://apihost http://apihost/schema.xsd") .build(); api = Feign.buil

Source from the content-addressed store, hash-verified

43 * contexts.
44 */
45public class JAXBEncoder implements Encoder {
46
47 private final JAXBContextFactory jaxbContextFactory;
48
49 public JAXBEncoder(JAXBContextFactory jaxbContextFactory) {
50 this.jaxbContextFactory = jaxbContextFactory;
51 }
52
53 @Override
54 public void encode(Object object, Type bodyType, RequestTemplate template) {
55 if (!(bodyType instanceof Class)) {
56 throw new UnsupportedOperationException(
57 "JAXB only supports encoding raw types. Found " + bodyType);
58 }
59 try {
60 Marshaller marshaller = jaxbContextFactory.createMarshaller((Class<?>) bodyType);
61 StringWriter stringWriter = new StringWriter();
62 marshaller.marshal(object, stringWriter);
63 template.body(stringWriter.toString());
64 } catch (JAXBException e) {
65 throw new EncodeException(e.toString(), e);
66 }
67 }
68}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected