square/retrofit — pull request #225 by adriancole (2013-05-26 23:05:35+00:00)
Title: add SAXConverter for XML deserialization

Per issue #193, this adds support for SAX XML deserialization, supported equally across java and android. STAX is also supported on android, but I personally use SAX more often.

This PR introduces `SAXConverter.Deserializer`, adding the ability to read the result of `ContentHandler`. A Deserializer is created per type, and this is expected to vary with implementations. Accordingly, `SAXConverter.newDeserializer(Type)` is marked abstract.

An example implementation could look look like this, though those using Dagger will surely optimize it.
```
static class STSConverter extends SAXConverter {
@Override
protected Deserializer newDeserializer(Type type) {
if (type == SessionCredentials.class)
return new SessionCredentialsHandler();
else if (type == AWSError.class)
return new AWSErrorHandler();
throw new UnsupportedOperationException("type not yet supported: " + type);
}

@Override
public TypedOutput toBody(Object object) {
// serializing to XML can be done many ways including
// something simple as StringBuilder or String.format
throw new UnsupportedOperationException();
}
}
```