All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tukeof.common.rest.xstream.XStreamXmlResponseBodyConverter Maven / Gradle / Ivy

The newest version!
package com.tukeof.common.rest.xstream;

import com.thoughtworks.xstream.XStream;
import okhttp3.ResponseBody;
import retrofit2.Converter;

import java.io.IOException;


final class XStreamXmlResponseBodyConverter implements Converter {

    private final Class cls;
    private final XStream xStream;

    XStreamXmlResponseBodyConverter(Class cls, XStream xStream) {
        this.cls = cls;
        this.xStream = xStream;
    }

    @Override
    @SuppressWarnings("unchecked")
    public T convert(ResponseBody value) throws IOException {
        try {
            this.xStream.processAnnotations(cls);
            T instance = cls.newInstance();
            this.xStream.fromXML(value.byteStream(), instance);
            return instance;

        } catch (IllegalAccessException | InstantiationException e) {
            throw new RuntimeException(e);
        } finally {
            value.close();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy