我尝试将 Activity 插入 Google 日历。
如果我直接使用 Java 对象创建事件,请使用 Java client ,我没问题。
我的问题是当我将 JSON 格式的事件发送到 Controller 时:(内容类型是 application/json,我使用 postman 或命令行发送它)
我的 JSON:
{
"summary": "Google I/O 2015",
"location": "800 Howard St., San Francisco, CA 94103",
"description": "A chance to hear more about Google\"s developer products.",
"start":{
"dateTime":"2018-04-07T17:00:00.000-04:00"
},
"end":{
"dateTime":"2018-04-07T18:00:00.000-04:00"
},
"attendees": [
{"email": "lpage@example.com"},
{"email": "sbrin@example.com"}
]
}
我的 Controller :
@PostMapping(path = "/new/event/{calendarId}/{sendNotification}")
public ResponseEntity<?> newEvent(@NonNull @PathVariable String calendarId,
@NonNull @PathVariable boolean sendNotification,
@NonNull @RequestBody Event event) {
Event eventCreated = postEventService.postNewEvent(calendarId, sendNotification, event);
return new ResponseEntity<>(eventCreated, HttpStatus.CREATED);
}
这是我的错误:
{
"status": 400,
"error": "Bad Request",
"message": "JSON parse error: Can not set com.google.api.services.calendar.model.EventDateTime field com.google.api.services.calendar.model.Event.start to java.util.LinkedHashMap; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not set com.google.api.services.calendar.model.EventDateTime field com.google.api.services.calendar.model.Event.start to java.util.LinkedHashMap (through reference chain: com.google.api.services.calendar.model.Event[\"start\"])",
"path": "/new/event/primary/true"
}
我的问题是完全相同的 JSON 在 Try this API 上完美运行在文档中。
预先感谢您的帮助!
最佳答案
您可以通过创建自定义 JSON 反序列化器来解决此错误。在 Spring Boot 中,您可以使用 @JsonComponent 注释来做到这一点。
关于java - Google 日历插入事件 : JSON parse error through @RequestBody Spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49690120/