【问题标题】:GenericJson doesn't retain null valueGenericJson 不保留空值
【发布时间】:2013-02-11 07:28:24
【问题描述】:

我正在用 Java 进行 Google 日历同步,遇到这样的问题: 我必须将 EventDateTime(GenericJson 的子类)发布到 Google 以同步时间。特别是在我的情况下,我必须清除“日期”字段,并设置“日期时间”字段。

   //code to init the variable dateTime, in the form of google DateTime
   EventDateTime edt = new EventDateTime();
   edt.put("dateTime", dateTime);
   edt.put("date", null);

当我使用上面的代码时,edt 中的地图只显示 1 个<key,value> 对:<dateTime,some date>。没有值对<date,null>

有人经历过吗?请帮助我解决方法。 tks。

更新:这个工作:edt.put ("date", Data.NULL_DATE_TIME),想法是进入Data的代码,找到对应的字段NULL_XXX并选择你需要的。

【问题讨论】:

    标签: google-api-java-client google-api-client


    【解决方案1】:

    尝试使用 Data.NULL_STRING 代替 null。

    有更多关于我们如何处理 JSON null here 的详细文档。

    注意:我是google-http-java-client 的项目所有者。

    【讨论】:

    • 您好,谢谢回复,抱歉回复晚了。当我尝试您的解决方案时,出现错误:ava.lang.IllegalArgumentException: Can not set com.google.api.client.util.DateTime field com.google.api.services.calendar.model.EventDateTime.dateTime to java.lang.String
    • 哦,NULL_DATE_TIME 有效,tks 。在我的帖子中更新,您能否更新您的答案,以便我可以打勾(仅供其他人立即看到),干杯。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    • 2012-08-31
    • 2018-08-29
    相关资源
    最近更新 更多