java - Google 日历插入事件 : JSON parse error through @RequestBody Spring

标签 java google-calendar-api

我尝试将 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/

相关文章:

java - 明确地我需要在 jssor slider 中发送 Autoplayinterval 选项

java - 如何使用不同的构造函数扩展一个类?

vb.net - Google 日历事件中缺少弹出式提醒

google-api - Google Calendar API V3 - 默认或主日历

google-apps-script - 使用 Google App 脚本创建 Google 日历提醒

java - 检测 sencha ext-gwt 3.0 树中的删除目标节点

java - 如何从图表创建最快的图像

google-apps-script - 如何在谷歌脚本上以字符串形式获取用户输入

java - 如何在常用词过滤器的java正则表达式中添加词列表

c# - Google Calendar API 身份验证 .NET 浏览器窗口