0

I've been following this article on how to get retrofit to work with xml... which works.

How to use Retrofit and SimpleXML together in downloading and parsing an XML file from a site?

But It needs to work with a callback. And I just cant get it work.

Has any one else done one?

public class LocksXmlDisplay {

@Root(name = "breakfast_menu")
public class BreakFastMenu
{
    @ElementList(inline = true)
    List<Food> foodList;
}

@Root(name="food")
public class Food
{
    @Element(name = "name")
    String name;

    @Element(name = "price")
    String price;

    @Element(name = "description")
    String description;

    @Element(name = "calories")
    String calories;
}

public BreakFastMenu breakFastMenu;

}

public interface GetKnocksInter {
@GET("/simple.xml")
//LocksXmlDisplay getxml();
void fetchxml(Callback<List<LocksXmlDisplay.Food>> mycallback);

}

            getKnocksInter.fetchxml(new Callback<List<LocksXmlDisplay.Food>>() {
            @Override
            public void success(List<LocksXmlDisplay.Food> foods, Response response) {

            }

            @Override
            public void failure(RetrofitError error) {

            }
        });
Community
  • 1
  • 1
aidanmack
  • 518
  • 1
  • 5
  • 16
  • What version of retrofit are you using? It's been updated to v2.0 recently and there has been some changes – GSala Oct 16 '15 at 21:02
  • Then it should work. Can you give more details about what doesn't work? Maybe put a log on the failure callback and post the error you get – GSala Oct 16 '15 at 21:07
  • So Ive just updated it to show locksXMLdisplay... and the error i get is java.lang.ClassCastException: libcore.reflect.ParameterizedTypeImpl cannot be cast to java.lang.Class – aidanmack Oct 16 '15 at 21:11
  • Im not sure what my callback should be returning.. – aidanmack Oct 16 '15 at 21:11
  • Hmmm, I have no Idea about that exception but maybe it has to do with the class you are trying to parse being inside another class? – GSala Oct 16 '15 at 21:13
  • @aidanmack could you throw in the XML that causes that exception? Your exception strongly suggests there's a problem with deserialization. – d4vidi Dec 08 '15 at 12:19

0 Answers0