我从frontend
- Angular 4传递了一个对象数组,其中一些是date
个对象,backend
中的对象被映射为LocalDateTime
。不幸的是,当我通过自己的反序列化器尝试deserialize
时,我得到了一个错误,这对我来说非常明显,但我无法解决它。所以我的java
类看起来像:
Deserializator
:
public class DateDeserialization extends JsonDeserializer<LocalDateTime> {
@Override
public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
return LocalDateTime.parse(jsonParser.getText());
}
}
我在model
课程中将deserializator
添加到字段中:
@JsonFormat(pattern = "MM-dd-yyyy")
@JsonDeserialize(using = DateDeserialization.class)
private LocalDateTime insertDate;
我的java controller
:
@RequestMapping(value = "", method = RequestMethod.POST)
public List<Guide> save(@RequestBody List<Guide> guides) {
guides.stream().forEach(x -> {
guideService.save(x);
});
return null;
}
我得到的error
是404 bad request
,error message
是:
JSON parse error: Text '{' could not be parsed at index 0; nested exception is com.fasterxml.jackson.databind.JsonMappingException
当然我知道这是什么意思但是如何解决呢?我还尝试了浏览器调试器在发送请求时传递给后端的内容:
0:{id: 1, description: "test1", insertDate: {…}, insertedBy: {…}, updateDate: {…}, …}
1:{id: 2, description: "test12", insertDate: {…}, insertedBy: {…}, updateDate: {…}, …}
2:{id: 3, description: "test13", insertDate: {…}, insertedBy: {…}, updateDate: {…}, …}
3:{id: 4, description: "test14", insertDate: {…}, insertedBy: {…}, updateDate: {…}, …}
4:{id: 5, description: "test15", insertDate: {…}, insertedBy: {…}, updateDate: {…}, …}
更新:
ngOnInit() {
this.guideService.getAll()
.subscribe(res => {
this.guides = res.json();
});
}
save(){
this.guideService.insertOrUpdate(this.guides).subscribe(res => {
console.log("test went")
});
}