Sometimes (very rarely, but anyway) you may need a service, that sends data to both Json and XML. Here’s how to do it:

Here we have Kotlin Coroutines (why not?), Retrofit, and two converters: Moshi for Json and Jaxb for XML

Now we need to create two new annotations:

Main magic. Custom converters factory:

Now we creating API with Retrofit:

And one simple data-class:

That’s all. Activity, start, logging results, applause:

And don’t forget premission on network access:

Code on my Gitlab

Leave a Reply

Close Menu