Jackson错误Java枚举映射

Jackson错误Java枚举映射,java,jackson,jersey,enum-map,Java,Jackson,Jersey,Enum Map,我正在尝试使用Jackson反序列化EnumMap,但遇到以下错误: 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.Rea

我正在尝试使用Jackson反序列化EnumMap,但遇到以下错误:

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]
以下是我用于密钥的枚举:

public enum ResultTypeEnum
{
    PRESETS,
    SUMMARY,
    TERMINATION,
    TIMESERIES
}
服务器代码如下所示:

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

        } catch (IllegalOperationException ex) {
            throw new InternalServerErrorException(ex);
        }
    }
@SuppressWarnings("unchecked")
    public EnumMap getAllResults() {
        return client.target(subjectURI + "results").request(MediaType.APPLICATION_JSON)
                .get(EnumMap.class);

    }
客户端代码如下所示:

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

        } catch (IllegalOperationException ex) {
            throw new InternalServerErrorException(ex);
        }
    }
@SuppressWarnings("unchecked")
    public EnumMap getAllResults() {
        return client.target(subjectURI + "results").request(MediaType.APPLICATION_JSON)
                .get(EnumMap.class);

    }
诊断结果类别如下:

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

    public DiagnoticResults() {
        super(ResultTypeEnum.class);
    }
}
公共类DiagnosticMap{
公共诊断结果(){
super(ResultTypeEnum.class);
}
}

这是我从另一个用户那里编写的一个类,该用户的EnumMap有问题。

我无法重现您的问题,所以我在这里进行猜测

客户端代码在创建
EnumMap
通过调用构造函数
EnumMap(类)
, 因为没有关于要使用哪种泛型类型的信息

因此,在客户端代码中,您应该将
EnumMap
替换为
diagnosticsults

而不是你的代码

@SuppressWarnings("unchecked")
public EnumMap getAllResults() {
    return client.target(subjectURI + "results").request(MediaType.APPLICATION_JSON)
            .get(EnumMap.class);
}
请尝试以下代码:

public DiagnoticResults getAllResults() {
    return client.target(subjectURI + "results").request(MediaType.APPLICATION_JSON)
            .get(DiagnoticResults.class);
}