3

I'm trying to use Jersey with Jackson in Android, but I got the following error:

Could not find class 'javax.xml.stream.XMLInputFactory', referenced from method org.glassfish.jersey.message.internal.MessagingBinders$MessageBodyProviders.configure

Here is my code:

public static List<Task> getAllTasks() {
  WebTarget target = client.target(TARGET).path(ALL_TASKS_RESOURCE)
        .queryParam("lang", "en");
  List<Task> tasks = target.request(MediaType.APPLICATION_JSON_TYPE)
        .get().readEntity(new GenericType<List<Task>>() {});
  return tasks;
}

I found out that StAX XML parser is not a part of Android, but there are some alternatives. I just don't understand why Jersey wants to stream XML, and not just fetch it from the server and let Jackson to map it to POJO?

Konstantin Milyutin
  • 11,946
  • 11
  • 59
  • 85

1 Answers1

0

If you are looking for a slick way to do HTTP on Android, I would avoid Jersey (it's a little heavy IMHO) and look at libraries like Retrofit. It's an annotation based REST client library that works really well. It has support for different serializers, supports async pretty well, etc.

The guys at Square have some pretty awesome libraries, including OkHttp - which is a way better http library than the built-in Apache one. It even supports SPDY and HTTP2.

toadzky
  • 3,806
  • 1
  • 15
  • 26