SAXDecoder implements Decoder { @Override public Object decode(Response response, Type type) throws IOException, DecodeException { if (response.body() == null) return null; ContentHandlerWithResult.Factory<?> handlerFactory = handlerFactories.get(type); checkState(handlerFactory != null, "type %s not in configured handlers %s", type, handlerFactories.keySet()); ContentHandlerWithResult<?> handler = handlerFactory.create(); try { XMLReader xmlReader = XMLReaderFactory.createXMLReader(); xmlReader.setFeature("http: xmlReader.setFeature("http: xmlReader.setFeature("http: xmlReader.setFeature("http: xmlReader.setFeature("http: xmlReader.setFeature("http: xmlReader.setContentHandler(handler); InputStream inputStream = response.body().asInputStream(); try { xmlReader.parse(new InputSource(inputStream)); } finally { ensureClosed(inputStream); } return handler.result(); } catch (SAXException e) { throw new DecodeException(response.status(), e.getMessage(), response.request(), e); } } private  SAXDecoder(Map<Type, ContentHandlerWithResult.Factory<?>> handlerFactories); static Builder builder(); @Override Object decode(Response response, Type type);  }
@Test public void parsesConfiguredTypes() throws ParseException, IOException { assertEquals(NetworkStatus.FAILED, decoder.decode(statusFailedResponse(), NetworkStatus.class)); assertEquals("Failed", decoder.decode(statusFailedResponse(), String.class)); }
@Test public void niceErrorOnUnconfiguredType() throws ParseException, IOException { thrown.expect(IllegalStateException.class); thrown.expectMessage("type int not in configured handlers"); decoder.decode(statusFailedResponse(), int.class); }