json - JSON array within an object is not being parsed
问题描述
I'm using hibernate, spring, and fasterxml/Jackson to create JSON based rest services.
I'm sending in the following 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
}
]
}
To be parsed into the following classes:
@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() {
}
}
I send that JSON into the following 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;
}
It parses the PartsRequest object just fine, but sets the partsRequestLines list to null. Can someone tell me how to get Jackson/REST to parse the sub-object list correctly?
解决方案
I figured it out. My method signature on the API was missing a @RequestBody annotation.
推荐阅读
- reactjs - 复选框标签中的值如何被推送到当前组件的状态数组
- laravel-5.8 - WithChunkReading 读取超出已填充最大行数的行
- angular - IdentityServer4:auth_time 丢失
- jquery - jQuery UI 滑块:默认值未显示
- mysql - 更新 db 用户的权限对现有连接有影响吗?
- json - Django - 如何渲染 html 并同时返回一个 json
- xamarin - (3D touch) 当用户杀死应用程序时,如何在应用程序中打开特定页面?
- kubernetes - kubernetes 中的 CrashLoopBackoff 错误中的 kube-controller-manager 和 kube-scheduler
- ios - 在城市飞艇门户上更改捆绑包 ID
- c# - 直接在游戏中绘制,而不是在屏幕中