2

Hello I am sorry if already asked but couldnt find.

Here is my problem, I do not know how many fields i will send to my webservice as they will be dynamic. As such i wanted to send a json array to my jersey jaxb ressource. as the objects in my json array will be a single dimensional array of strings i should be able to do the below:

  @POST
    @Path("/test")
    @Produces(MediaType.APPLICATION_JSON)
    public Response InputList(@QueryParam("list") final List<String> inputList)

Here is my json array { "list": [ "hello", "world" ] }

This does not seems to work....

1 Answer 1

3

What you have now doesn't work because your JSON doesn't represent a list of strings. It represents an object that has a single property which is a list of strings. To wit:

["hello", "world"]

Is a simple JSON data stream that can be deserialized directly into a List<String> in Java. Whereas:

{"list" : ["hello", "world"]}

Is a more complex data stream that needs to be deserialized into an object, for example one that looks like this:

public class ListHolder {
    private List<String> list;

    // constructors, getters/setters
}

You can then use this in your Jersey resource:

@POST
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public Response InputList(@QueryParam("list") final ListHolder listHolder) {
    final List<String> list = listHolder.getList();
    // rest of code
}
Sign up to request clarification or add additional context in comments.

1 Comment

@Fongios - thats a totally separate question and should be posted as such.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.