5
votes

In my current setup I use Jersey 2.0 with MOXy as discribed in jersey docs. I rely completely on the “Auto-Discoverable Features”, so I do not use any extra configuration or JAXB annotation.

My task is to deserialize an array of strings on the server side. The client is sending the JSON message:

["foo","bar"]

And on the server side the following method header should deserialize it:

@POST
@Path("/stringArray")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response stringArray(List<String> stringList) {
   ...
}

Problem: The content of stringList is {null,null}, so the amount of elements is always correct, but the strings are set to null.

The same with a small wrapper class is working. Here the class:

public static class Data {
   public List<String> stringList;
}

Changing methode signature to stringArray(Data data) and changing the JSON message to:

{"stringList": ["foo","bar"]}

What is the difference between the two approaches and how can I get the plain string array working?

Update: The described problem is fixed by answer from @Blaise. But the closely related problem of serializing a List of POJOs does still not work. Message:

[org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=class java.util.ArrayList.]

The only solution I found is again using a small wrapper class containing the List...

1
In general it seems to be difficult to serialize/deserialize Collections e.g. List<?> without wrapping them in a class. Can somebody confirm that? - adler
Problem solved by using org.eclipse.persistence.core_2.5.1.v20130706-f712d02.jar and org.eclipse.persistence.moxy_2.5.1.v20130706-f712d02.jar instead of the 2.5.0 versions. Thanks to @blaise - adler

1 Answers

3
votes

The issue you are seeing is due to a bug in EclipseLink JAXB (MOXy):

This bug has been fixed in the EclipseLink 2.5.1 and 2.6.0 streams. You can download a nightly build starting July 5, 2013 from the following link: