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.
I was not able to reproduce your problem, so I'm kind of guessing here.
It seems the client-code has problems in creating an
EnumMap<K, V>
by calling the constructorEnumMap(Class<K>)
, because there is no information about which generic typeK
type to use.Therefore, in your client-code you should replace
EnumMap
byDiagnoticResults
.Instead of your code
try this code: