Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未分析对象中的JSON数组_Json_Hibernate_Spring Mvc - Fatal编程技术网

未分析对象中的JSON数组

未分析对象中的JSON数组,json,hibernate,spring-mvc,Json,Hibernate,Spring Mvc,我正在使用hibernate、spring和fasterxml/Jackson创建基于JSON的rest服务 我将发送以下JSON: { "allParts" : true, "aogLocation" : "LAS", "companyId" : "20", "controlNo" : "1", "controlSeq" : "1234", "dateNeeded" : "2020-02-24", "timeNeeded" : "800

我正在使用hibernate、spring和fasterxml/Jackson创建基于JSON的rest服务

我将发送以下JSON:

{

    "allParts" : true,
    "aogLocation" : "LAS",
    "companyId" : "20",
    "controlNo" : "1",
    "controlSeq" : "1234",
    "dateNeeded" : "2020-02-24",
    "timeNeeded" : "800",
    "employeeId" : "bob",
    "inventoryLocation" : "LAS",
    "requestType" : "STOCK",
    "shippingAddress": "123 e. st. Las Vegas, NV 12345",
    "tailNo" : "abc",
    "partsRequestLines" : [
        {
            "location": "LAS",
            "lineNote" : "I need this part really bad",
            "requestedPartDescription" : "it makes a plane go.",
            "requestedPartNumber" : "abc-123",
            "requestedQuantity" : 10
        }
    ]
}
要解析为以下类:

@Getter
@Setter
public class PartsRequestDto extends AbstractDto {

    private Boolean allParts;
    private String aogLocation;
    private Date chgdate;
    private Integer chgpage;
    private String chgprog;
    private String chgtype;
    private String chguser;
    private String companyId;
    private String controlNo;
    private Integer controlSeq;
    private Date dateNeeded;
    private String employeeId;
    private String inventoryLocation;
    private Date requestDate;
    private Integer requestId;
    private String requestType;
    private String shippingAddress;
    private Integer status;
    private Timestamp sysEnd;
    private Timestamp sysStart;
    private String tailNo;
    private String timeNeeded;
    private Timestamp transStart;

    private List<PartsRequestLineDto> partsRequestLines;

    public PartsRequestDto() {

    }

    public PartsRequestDto(Boolean allParts, String aogLocation, Date chgdate, Integer chgpage, String chgprog,
                           String chgtype, String chguser, String companyId, String controlNo, Integer controlSeq,
                           Date dateNeeded, String employeeId, String inventoryLocation, Date requestDate, Integer requestId,
                           String requestType, String shippingAddress, Integer status, Timestamp sysEnd, Timestamp sysStart,
                           String tailNo, String timeNeeded, Timestamp transStart) {
        this.allParts = allParts;
        this.aogLocation = aogLocation;
        this.chgdate = chgdate;
        this.chgpage = chgpage;
        this.chgprog = chgprog;
        this.chgtype = chgtype;
        this.chguser = chguser;
        this.companyId = companyId;
        this.controlNo = controlNo;
        this.controlSeq = controlSeq;
        this.dateNeeded = dateNeeded;
        this.employeeId = employeeId;
        this.inventoryLocation = inventoryLocation;
        this.requestDate = requestDate;
        this.requestId = requestId;
        this.requestType = requestType;
        this.shippingAddress = shippingAddress;
        this.status = status;
        this.sysEnd = sysEnd;
        this.sysStart = sysStart;
        this.tailNo = tailNo;
        this.timeNeeded = timeNeeded;
        this.transStart = transStart;
    }
}




@Getter
@Setter
@AllArgsConstructor
public class PartsRequestLineDto implements Serializable {
    private Integer id;
    private Integer reqId;
    private String location;

    private String requestType;
    private Date etaTimestamp;
    private Date neededTimestamp;
    private Date requestedTimestamp;
    private Integer status;
    private String tailNumber;
    private String lineNote;
    private String packingListId;
    private String requestedPartDescription;
    private String requestedPartNumber;
    private Integer requestedQuantity;

    public PartsRequestLineDto() {

    }
}

它可以很好地解析PartsRequest对象,但会将partsRequestLines列表设置为null。有人能告诉我如何让Jackson/REST正确解析子对象列表吗?

我找到了答案。API上的方法签名缺少@RequestBody注释

@RequestMapping(value = "/create", method = RequestMethod.POST)
public PartsRequestDto createPartsRequest(PartsRequestDto partsRequestDto) throws Exception {
    PartsRequest partsRequest = partsRequestService.constructPartsRequestFromDto(partsRequestDto);
    PartsRequestDto response = partsRequestService.createPartsRequest(partsRequest);
    return response;
}