美文网首页
retrofit xml json

retrofit xml json

作者: lyzaijs | 来源:发表于2016-11-24 10:46 被阅读50次

http://stackoverflow.com/questions/27436266/how-to-post-json-but-get-xml-response-using-retrofit

mRestAdapter = new RestAdapter.Builder()
                    .setEndpoint(getBaseUrl())
                    .setConverter(new SimpleXMLConverter())
                    .build();

result

public class MixedConverter implements Converter {
      private Converter mSerializer;
      private Converter mDeserializer;

    public MixedConverter(Converter serializer, Converter deserializer) {
        mSerializer = serializer;
        mDeserializer = deserializer;
    }


    @Override
    public Object fromBody(TypedInput body, Type type) throws ConversionException {
        return mDeserializer.fromBody(body, type);
    }

    @Override
    public TypedOutput toBody(Object object) {
        return mSerializer.toBody(object);
    }
}

and

.setConverter(new MixedConverter(new SimpleXMLConverter(), new GsonConverter(gson)));

相关文章

网友评论

      本文标题:retrofit xml json

      本文链接:https://www.haomeiwen.com/subject/cijbpttx.html