Home » Java » Jackson Error Java EnumMap

Jackson Error Java EnumMap

Posted by: admin May 17, 2018 Leave a comment

Questions:

I am trying to deserialize an EnumMap with Jackson, and I am running into the following error:

javax.ws.rs.client.ResponseProcessingException: com.fasterxml.jackson.databind.JsonMappingException: Can not construct EnumMap; generic (key) type not available
 at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@793ff30f; line: 1, column: 1]

Here’s the enum I’m using for the keys:

public enum ResultTypeEnum
{
    PRESETS,
    SUMMARY,
    TERMINATION,
    TIMESERIES
}

The server code is this:

@GET
    @Path("/results")
    @Produces(MediaType.APPLICATION_JSON)
    public DiagnoticResults getAllResults() {
        try {
            return subjectService.onGetAllResults();

        } catch (IllegalOperationException ex) {
            throw new InternalServerErrorException(ex);
        }
    }

The client code is this:

@SuppressWarnings("unchecked")
    public EnumMap getAllResults() {
        return client.target(subjectURI + "results").request(MediaType.APPLICATION_JSON)
                .get(EnumMap.class);

    }

The diagnostic results class is this:

public class DiagnoticResults extends EnumMap<ResultTypeEnum, byte[]> {

    public DiagnoticResults() {
        super(ResultTypeEnum.class);
    }
}

This is a class I wrote from another user that was having issues with an EnumMap.

Answers: