How to transfer a List of Primitive with Jersey + JAXB + JSON

Question!

This code works fine if I transfer a class ( MyClass ) that has @XmlRoolElement

Client

WebResource webResource = restClient.resource(getRessourceURL());
return webResource.get( new GenericType<List<MyClass>>(){} );

But if I try to transfer a primitive, like String, Integer, Boolean, etc...

Client

WebResource webResource = restClient.resource(getRessourceURL());
return webResource.get( new GenericType<List<Integer>>(){} );

I am getting the error :

unable to marshal type "java.lang.Integer" as an element because it is missing an @XmlRootElement annotation

I get exactly the same result when sending an entity parameter to my request:

Client

WebResource webResource = restClient.resource(getRessourceURL());
return webResource.post( new GenericType<List<Integer>>(){}, Arrays.toList("1"));

Server

@GET
@Path("/PATH")
@Produces(MediaType.APPLICATION_JSON)
public List<MyClass> getListOfMyClass( List<Integer> myClassIdList)
{
  return getMyClassList(myClassIdList);
}

Is there a way to tranfer this kind of list without creating a wrapper class for each of these primitive type?? Or am I missing something obvious?



Answers

I've found a work around by controlling the un-/marshalling by hand, without Jersey.

Client

WebResource webResource = restClient.resource(getRessourceURL());
return webResource.post( new GenericType


This video can help you solving your question :)
By: admin