Я использую 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
и сломать мой остаток кода, что я сделал не так?