users@jersey.java.net

[Jersey] Re: Jersey 2.3.1 on Android, why not?

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Tue, 5 Nov 2013 18:24:21 +0100

On 21 Oct 2013, at 00:05, Marko Matić <cipiripper_at_gmail.com> wrote:

> Hi all.
>
> I am trying to make Jersey 2.3.1 work on Android, but with some "success". I managed to repack Jersey 2.3.1 and all its dependencies, plus some more Javax APIs missing on Android using JarJar, it can be compiled now to APK, executed on DalvikVM - but still not working completely...
>
> I can make it send (post/put) requests and receive responses that are both of String.class - I can't use the POJO way of using Jersey - meaning if I execute this: webTarget.request("*").get().readEntity(Companies.class) I get this: http://pastebin.com/Q8FhnEKW - (see line 51) - even though MIME type of data returned is "***+json" Jersey can't recognize it.
>
> But if I execute this (with String.class): webTarget.request("*").get().readEntity(String.class) I get the string response, but with many warnings like: "Unable to match class for part: 'Ljava/awt/image/RenderedImage;'" (full log here: http://pastebin.com/Sq2DL2ty).
>
> For now I fixed this to always get String.class and then use Jackson ObjectMapper to deserialize that stringified JSON to POJO of the given class, and this works... slow.
>
>
> So, my questions are:
>
> 1. Why can it be (if you look at my full error log) that JSON string is not deserialized to POJO? Am I missing some configuration between Jackson and Jersey (I use the latest versions of both)?

Jersey does not have JSON support enabled by default - you need to enable it explicitly:
https://jersey.java.net/documentation/2.4/media.html#json
Did you do it?

> 2. Is there some hidden Android Jersey version available that works out of the box? :)

No. AFAIK.

> 3. Can I turn off org.glassfish.jersey.message.internal.RenderedImageProvider from code, without any compiling, repackaging...? Because I see that it is giving me problems because it wants to use RenderedImage class from AWT which is pointless on Android... and this slows down my requests.

No. You should file a new enhancement (improvement) request in Jersey JIRA (https://java.net/jira/browse/JERSEY) to get it resolved. Ideally, you can also contribute (https://jersey.java.net/scm.html#/Submitting_Patches_and_Contribute_Code) the fix via GitHub pull request.

Marek
>
>
> Thanks in advance!
> Marko