将String转换为Java Object并获取nullpointerexception

时间:2019-05-29 13:22:02

标签: java

我有以下字符串。我想将字符串的内容映射到pojo类。当我这样做时,我得到了nullpointer异常。

字符串是=

String response = "data":{"uploadTime":"29/05/2019 06:43:33 PM","totRecCount":"1","successRecCount":"0","errorCount":"1","fileName":"test1.json","fileReference":"10205095","links":{"linkDetails":[],"empty":true}},"links":{"linkDetails":[{"href":"http:localhost:9078/plan/CUS01/SCH/F75551/employer/EMP000820048/files/payroll/10205095","contentType":"application/json","relationDesc":"employer","httpVerb":"GET"}],"empty":false},"errors":{"empty":true,"errorDetails":[]}

班级回应

@JsonIgnoreProperties(ignoreUnknown = true)
public class PlanEmployerFileUploadResponse {

    public PlanEmployerFileUploadResponse(Data data, Links links, Errors errors) {

    public PlanEmployerFileUploadResponse() {
        super();
    }

    Data data;
    Links links;
    Errors errors;
    }

分类数据

@JsonIgnoreProperties(ignoreUnknown = true)
public class Data {

    public Data() {
        super();
    }
    String uploadTime;
    String totRecCount;
    String successRecCount;
    String errorCount;
    String fileName;
    String fileReference;
    Links links;
    }

类链接

@JsonIgnoreProperties(ignoreUnknown = true)
public class Links {

    public Links() {
        super();
    }

    List<LinkDetail> linkDetails;
    boolean empty;
}

LinkDetails类

@JsonIgnoreProperties(ignoreUnknown = true)
public class LinkDetail {

    public LinkDetail() {
        super();
    }
    String conTentType;
    String href;
    String httpVerb;
    String relationDesc;
}

类错误

public class Errors {

    public Errors() {
        super();
    }
    boolean empty ;
    List<ErrorDetails> errorDetail;
}

我写了

ObjectMapper obj= new objectMapper();
PlanEmployerFileUploadResponse  pe;
pe =obj.readvalue(response,PlanEmployerFileUploadResponse.class);

Bu我得到的错误是nullpointerexception。

0 个答案:

没有答案