Java Microsoft动态CRM日期时间字段错误

Java Microsoft动态CRM日期时间字段错误,java,datetime,crm,Java,Datetime,Crm,我正在使用Java连接到Dynamic CRM online。我可以创建除datetime以外的任何类型的字段。每当我添加DateTime字段时,就会出现以下错误 [错误]格式化程序在尝试反序列化消息时引发异常:尝试反序列化参数时出错。InnerException消息是“第1行位置9875出错”命名空间“”中的EndElement“”KeyValuePairOfstringanyType“”不应为空。应为元素“值”。有关更多详细信息,请参阅InnerException 我的代码片段是这样的 Or

我正在使用Java连接到Dynamic CRM online。我可以创建除datetime以外的任何类型的字段。每当我添加DateTime字段时,就会出现以下错误

[错误]格式化程序在尝试反序列化消息时引发异常:尝试反序列化参数时出错。InnerException消息是“第1行位置9875出错”命名空间“”中的EndElement“”KeyValuePairOfstringanyType“”不应为空。应为元素“值”。有关更多详细信息,请参阅InnerException

我的代码片段是这样的

OrganizationServiceStub.DateTime d= new OrganizationServiceStub.DateTime();
Calendar c = Calendar.getInstance();
d.setDateTime(c);
collection.addKeyValuePairOfstringanyType(pair("startdate",d));

您不必使用
OrganizationServiceStub.DateTime
。您正在使用的存根提供了允许您传递任何数据类型值的
OrganizationServiceStub.KeyValuePairOfstringanyType
。我们必须知道字段值的类型并传递特定类型

在您的情况下,要传递
日期
,mircosoft crm将日期字段设置为
GregoriaCalendar
,因此我们只需要发送这种类型的数据。下面是代码

Date date = new SimpleDateFormat("MM/dd/yy").parse("06/29/15");
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);

OrganizationServiceStub.AttributeCollection collection = new OrganizationServiceStub.AttributeCollection();
OrganizationServiceStub.KeyValuePairOfstringanyType dateattr = new OrganizationServiceStub.KeyValuePairOfstringanyType();
dateattr.setKey("startdate");
dateattr.setValue(date);
collection.addKeyValuePairOfstringanyType(dateattr);