Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jersey-dev] Consuming JSON list of strings sent via POST

Given a function that processes a request, annotated like the following

    @Path("/something")
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public Response SomeFunction(@Context HttpServletRequest request) {

And assuming that a valid request with `Content-type: application/json` is received by Jersey, with the body something like `["a", "b"]` -- in other words, a JSON list of strings -- what is the easiest way to have Jersey automagically parse the body into a parameter for the function? I am using Jackson for JSON de/serialization.

I tried adding `List<String> foos` as a parameter, i.e.:

    public Response SomeFunction(List<String> foos, @Context HttpServletRequest request) {

But this fails with the message:

    Cannot deserialize instance of java.util.ArrayList out of VALUE_STRING token
    at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 1]

I've combed the web for examples, but many follow this pattern, and so it *should* work...

Am I missing some configuration step somewhere?

T



Back to the top