@@ -47,8 +47,9 @@ public void encodesXml() throws Exception {
4747 new JAXBEncoder (new JAXBContextFactory .Builder ().build ())
4848 .encode (mock , MockObject .class , template );
4949
50- assertThat (template ).hasBody (
51- "<?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" yes\" ?><mockObject><value>Test</value></mockObject>" );
50+ assertThat (template )
51+ .hasBody (
52+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" yes\" ?><mockObject><value>Test</value></mockObject>" );
5253 }
5354
5455 @ Test
@@ -122,11 +123,14 @@ public void encodesXmlWithCustomJAXBNoNamespaceSchemaLocation() throws Exception
122123 RequestTemplate template = new RequestTemplate ();
123124 encoder .encode (mock , MockObject .class , template );
124125
125- assertThat (template ).hasBody ("<?xml version=\" 1.0\" encoding=\" UTF-8\" " +
126- "standalone=\" yes\" ?><mockObject xsi:noNamespaceSchemaLocation=\" http://apihost/schema.xsd\" "
127- +
128- "xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" >" +
129- "<value>Test</value></mockObject>" );
126+ assertThat (template )
127+ .hasBody (
128+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" "
129+ +
130+ "standalone=\" yes\" ?><mockObject xsi:noNamespaceSchemaLocation=\" http://apihost/schema.xsd\" "
131+ +
132+ "xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" >" +
133+ "<value>Test</value></mockObject>" );
130134 }
131135
132136 @ Test
@@ -178,9 +182,11 @@ public void decodesXml() throws Exception {
178182
179183 @ Test
180184 public void doesntDecodeParameterizedTypes () throws Exception {
181- thrown .expect (UnsupportedOperationException .class );
185+ thrown .expect (feign . codec . DecodeException .class );
182186 thrown .expectMessage (
183- "JAXB only supports decoding raw types. Found java.util.Map<java.lang.String, ?>" );
187+ "java.util.Map is an interface, and JAXB can't handle interfaces.\n "
188+ + "\t this problem is related to the following location:\n "
189+ + "\t \t at java.util.Map" );
184190
185191 class ParameterizedHolder {
186192
@@ -199,6 +205,44 @@ class ParameterizedHolder {
199205 new JAXBDecoder (new JAXBContextFactory .Builder ().build ()).decode (response , parameterized );
200206 }
201207
208+ @ XmlRootElement
209+ static class Box <T > {
210+
211+ @ XmlElement
212+ private T t ;
213+
214+ public void set (T t ) {
215+ this .t = t ;
216+ }
217+
218+ }
219+
220+ @ Test
221+ public void decodeAnnotatedParameterizedTypes () throws Exception {
222+ JAXBContextFactory jaxbContextFactory =
223+ new JAXBContextFactory .Builder ().withMarshallerFormattedOutput (true ).build ();
224+
225+ Encoder encoder = new JAXBEncoder (jaxbContextFactory );
226+
227+ Box <String > boxStr = new Box <>();
228+ boxStr .set ("hi" );
229+ Box <Box <String >> boxBoxStr = new Box <>();
230+ boxBoxStr .set (boxStr );
231+ RequestTemplate template = new RequestTemplate ();
232+ encoder .encode (boxBoxStr , Box .class , template );
233+
234+ Response response = Response .builder ()
235+ .status (200 )
236+ .reason ("OK" )
237+ .request (Request .create ("GET" , "/api" , Collections .emptyMap (), null , Util .UTF_8 ))
238+ .headers (Collections .<String , Collection <String >>emptyMap ())
239+ .body (template .body ())
240+ .build ();
241+
242+ new JAXBDecoder (new JAXBContextFactory .Builder ().build ()).decode (response , Box .class );
243+
244+ }
245+
202246 /** Enabled via {@link feign.Feign.Builder#decode404()} */
203247 @ Test
204248 public void notFoundDecodesToEmpty () throws Exception {
0 commit comments