Jersey GenericEntity<Collection<String>> Exception

Viewed 45

Hi my Spring application is throwing the following exception when excecuting the following code:

@GET
    @Path("/categories")
    @Produces(value = {MediaType.APPLICATION_JSON})
    public Response getCategories() {
        LOGGER.info("Accessed /jobs/categories GET controller");
        final Collection<String> categories = jobService.getJobsCategories().stream().map(Enum::name).collect(Collectors.toList());
        final Collection<Integer> aux = Arrays.asList(1,2,3);
        return Response.ok(new GenericEntity<Collection<String>>(categories){}).build();
    }

Exception: ago 05, 2021 2:26:48 PM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo GRAVE: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.Collection<java.lang.String>.

I don't know what's wrong, I have no problem when wrapping user-defined classes like User (with getters, setters and default constructor). The problem is when using classes like Integer/Long/String...

I've seen this problem around but no good answer to it.

0 Answers
Related