Я использую hibernate, spring и fastxml / Jackson для создания служб отдыха на основе JSON.
Я отправляю следующее 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() {
}
}
Я отправляю этот JSON в следующий REST API:
@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;
}
Он отлично разбирает объект PartsRequest, но устанавливает partsRequestLines список к нулю. Может кто-нибудь сказать мне, как заставить Джексона / REST правильно проанализировать список подобъектов?