Lombok Builder和Jackson的Getter返回null

时间:2019-02-05 14:42:10

标签: java spring-boot jackson lombok

我在我的Spring Boot项目中使用Lombok版本1.18.0,这是我在Postman中使用的请求正文。

{
    "RetailTransactionGenericRequest":{
        "dateTime": "2019-02-04T16:50:40.740Z",
        "origin":{
            "retailerName":"retailerName",
            "accessID":"accessID",
            "currencyCode": "CAD",
            "storeID":"storeID",
            "termID": "terminalID"
        },
        "product":{
            "amount": 20,
            "code":"code",
            "upc":"UPC"
        },
        "transactionID": "201902041650403164912"
    }
}

我的实体:

package entity;
// imports

@Data
@Builder(builderClassName = "RetailTransactionGenericRequestWrapperBuilder", toBuilder = true)
@JsonDeserialize(builder = RetailTransactionGenericRequestWrapper.RetailTransactionGenericRequestWrapperBuilder.class)
public class RetailTransactionGenericRequestWrapper {
    @JsonProperty
    private RetailTransactionGenericRequest RetailTransactionGenericRequest;

    @JsonPOJOBuilder(withPrefix = "")
    public static class RetailTransactionGenericRequestWrapperBuilder{

    }

    @Override
    public String toString(){
        return ReflectionToStringBuilder.toString(this, ToStringStyle.JSON_STYLE);
    }
}
package com.itsp.incommcall.entity;

//imports

@Data
@Getter
@Builder(builderClassName = "RetailTransactionGenericRequestBuilder", toBuilder = true)
@JsonDeserialize(builder = RetailTransactionGenericRequest.RetailTransactionGenericRequestBuilder.class)
public class RetailTransactionGenericRequest {

    @JsonProperty
    private String dateTime;
    @JsonProperty
    private Origin origin;
    @JsonProperty
    private Product product;
    @JsonProperty
    private String transactionID;

    @JsonPOJOBuilder(withPrefix = "")
    public static class RetailTransactionGenericRequestBuilder{

    }

    @Override
    public String toString(){
        return ReflectionToStringBuilder.toString(this, ToStringStyle.JSON_STYLE);
    }

}
package entity;
//imports

@Data
@Getter
@Builder(builderClassName = "OriginBuilder", toBuilder = true)
@JsonDeserialize(builder = Origin.OriginBuilder.class)
public class Origin {

    @JsonProperty
    @Builder.Default
    private String accessID = "default id";

    @JsonProperty

    private String currencyCode;

    @JsonProperty
    @Builder.Default
    private String retailerName = "default retail name";

    @JsonProperty
    private String storeID;

    @JsonProperty
    private String termID;

    @JsonProperty
    private String posEntryMode;

    @JsonPOJOBuilder(withPrefix = "")
    public static class OriginBuilder {

    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.JSON_STYLE);
    }
}
package entity;
//imports

@Data
@Getter
@Builder(builderClassName = "ProductBuilder", toBuilder = true)
@JsonDeserialize(builder = Product.ProductBuilder.class)
public class Product {

    @JsonProperty
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private double amount;

    @JsonProperty
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String code;

    @JsonProperty
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String upc;

    // Response part
    @JsonProperty
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private MetaFields metafields;

    @JsonProperty
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String balance;

    @JsonProperty
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String status;


    @JsonPOJOBuilder(withPrefix = "")
    public static class ProductBuilder{

    }

    @Override
    public String toString(){
        return ReflectionToStringBuilder.toString(this, ToStringStyle.JSON_STYLE);
    }
}

在控制器类中,我在控制器方法中使用了参数@RequestBody RetailTransactionGenericRequestWrapper wrapper,当我尝试通过调用RetailTransactinGenericRequest访问wrapper.getRetailTransactinGenericRequest对象时,我得到了null ,然后分解其余的代码,我做错了什么?

0 个答案:

没有答案