【发布时间】:2019-04-19 11:33:37
【问题描述】:
我已经使用 Angular 将对象数组发送到 Api 以进行后期操作,这与 3 个对象的数组一起使用:
我想在 java 中这样做,所以我在 java 中将类初始化为:
SLDto.java
public class SLDto {
private LetterDto letterDto;
private List<DocumentDto> documentDto;
private List<SelectionCustomOfficeDto> selectionCustomOfficeDto;
public SLDto() {
}
//i omitted getters and setters here
}
LetterDto.java
public class LetterDto {
private int clkletter;
private String inOut;
private String inOutNo;
private String inOutDate;
private String letterIssuedSubBy;
private String letterFile;
private String representativeName;
private int assessmentNo;
private int selectionNo;
public LetterDto() {
}
DocumentDto.java
public class DocumentDto {
private int docId;
private String docName;
private boolean checked;
public DocumentDto() {
}
}
SelectionCustomOfficeDto.java
public class SelectionCustomOfficeDto {
private int id;
private String fromDate;
private String toDate;
private int consignmentNo;
private int selectionId;
private int customOfficeId;
private String custOfficeName;
private String selectionName;
}
我需要将客户端对象映射到 Api,所以我使用了该方法:
@PostMapping(value = "/letter/create")
public String postAllOne(@RequestBody SLDto sldto ) {
//i tried 2ways to see the json data or trace it and assign into
respective objects but i am not getting.I tried
1st method
System.out.println(sldto.getLetterDto()); //Not working
2nd method
for(LetterDto letterDto:sldto.getLetterDto()) {
//it is not allowing me
}
return "success";
}
它不允许我映射为:
如何将 3json 数据分离到各自的对象中?
[{"inOutNo":"2018-11-12","inOutDate":"2","inOut":"AnnexOne","letterFile":null,"representativeName":null,"assessmentNo":0,"letterIssuedSubBy":null,"selectionNo":8},[{"docId":1,"docName":"proforma invoice","checked":true},{"docId":2,"docName":"Packing list","checked":true}],[{"customOfficeId":"1","fromDate":"2018-11-12","toDate":"2018-11-20","consignmentNo":2,"selectionId":8,"selectionName":"PCS","custOfficeName":"Bhairawa Bhansar"}]]
看到的错误是
我收到类似
的错误"DefaultHandlerExceptionResolver : 已解决 [org.springframework.http.converter.HttpMessageNotReadableException: JSON 解析错误:无法反序列化 com.ashwin.springsecurityangular.dto.SLDto out of START_ARRAY token; 嵌套异常是 com.fasterxml.jackson.databind.exc.MismatchedInputException:不能 反序列化 com.ashwin.springsecurityangular.dto.SLDto 的实例 START_ARRAY 令牌”
【问题讨论】:
-
根据您的班级定义
letterDto不是collection也不是array。是错字吗? -
我收到类似“DefaultHandlerExceptionResolver: Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of
com.ashwin.springsecurityangular.dto.SLDtoout of START_ARRAY token; 嵌套异常是 com.fasterxml .jackson.databind.exc.MismatchedInputException:无法从 START_ARRAY 令牌中反序列化com.ashwin.springsecurityangular.dto.SLDto的实例” -
好的 - 您的帖子中似乎存在编译时错误,因此问题是。
-
你能发布输入json吗
-
我在页首贴了一张图片,请看
标签: java arrays json spring spring-boot