Java 使用ApacheOlingo指定实体类型

Java 使用ApacheOlingo指定实体类型,java,odata,dynamics-crm,crm,olingo,Java,Odata,Dynamics Crm,Crm,Olingo,我在我的项目中使用ApacheOlingoV4Java库,它工作得很好。谢谢 我在调用一个特定端点时遇到问题- https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/merge?view=dynamics-ce-odata-9 问题:无法在请求中指定实体类型。无法确定是否必须将其作为批注或其他内容传入。我尝试将其作为参数传入,但库随后将其类型附加为字符串参数 请求正文应包含: "@odata.t

我在我的项目中使用ApacheOlingoV4Java库,它工作得很好。谢谢

我在调用一个特定端点时遇到问题-

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/merge?view=dynamics-ce-odata-9
问题:无法在请求中指定实体类型。无法确定是否必须将其作为批注或其他内容传入。我尝试将其作为参数传入,但库随后将其类型附加为字符串参数

请求正文应包含:

    "@odata.type": "Microsoft.Dynamics.CRM.account"
实际请求正文包含:

    "@odata.type@odata.type": "String", 
    "@odata.type": "Microsoft.Dynamics.CRM.account"
上面的请求在crm内部导致异常,因为他们不需要此参数

An error occurred while validating input parameters: Microsoft.OData.ODataException: Does not support untyped value in non-open type.
  at System.Web.OData.Formatter.Deserialization.DeserializationHelpers.ApplyProperty(ODataProperty property, IEdmStructuredTypeReference resourceType, Object resource, ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)
  at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.ApplyStructuralProperties(Object resource, ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
  at Microsoft.Crm.Extensibility.OData.CrmODataEntityDeserializer.ApplyStructuralProperties(Object resource, ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
  at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.ReadResource(ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
  at Microsoft.Crm.Extensibility.OData.CrmODataActionPayloadDeserializer.ReadEntry(ODataDeserializerContext readContext, ODataParameterReader reader, IEdmOperationParameter parameter)
  at Microsoft.Crm.Extensibility.OData.CrmODataActionPayloadDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)
  at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) [HTTP/1.1 400 Bad Request]
我曾尝试将注释附加到对象,但这些注释最终不会出现在请求体中

作为参考,以下请求正文使用postman普通旧http客户端工作:

{
    "Target": {
        "accountid": "b68c98c3-f339-e811-eeee-000d3a137a33",
        "@odata.type": "Microsoft.Dynamics.CRM.account"
    },
    "Subordinate": {
        "accountid": "f89a8c95-2353-e811-wwww-000d3a137896",
        "@odata.type": "Microsoft.Dynamics.CRM.account"
    },
    "UpdateContent": {
        "websiteurl": "testdata.com",
        "@odata.type": "Microsoft.Dynamics.CRM.account"
    },
    "PerformParentingChecks": "false"
} 

提前感谢您抽出时间来帮助我。

在尝试使用类型系统时,使用Olingo客户端库可能会很健谈。请在groovy中查看下面的代码片段,看看它是否有用:

static AbstractODataInvokeRequest buildMergeRequest(ODataClient client, URI mergeUri,
        String targetLeadIdStr, String subLeadIdStr) {
    Map<String, ClientValue> params = [:]
    params.put("Target", buildEntityIdComplex(client, "leadid", targetLeadIdStr))
    params.put("Subordinate", buildEntityIdComplex(client, "leadid", subLeadIdStr))
    params.put("UpdateContent", buildEntityIdComplex(client, "leadid", "00000000-0000-0000-0000-000000000000"))
    params.put("PerformParentingChecks", client.getObjectFactory().newPrimitiveValueBuilder().buildBoolean(false))

    AbstractODataInvokeRequest funcReq =
            client.getInvokeRequestFactory().getActionInvokeRequest(mergeUri, ODataError.class, params)
                    .addCustomHeader("Authorization", "Bearer ${accessToken}")
    funcReq.setFormat(ContentType.JSON_NO_METADATA)
    return funcReq;
}

static ClientComplexValue buildEntityIdComplex(ODataClient client, String entityIdName, String entityIdValStr) {
    ClientComplexValue targetLeadId = client.getObjectFactory().
            newComplexValue("Microsoft.Dynamics.CRM.lead")
    targetLeadId.add(client.getObjectFactory().newPrimitiveProperty(entityIdName,
            client.getObjectFactory().newPrimitiveValueBuilder().buildGuid(buildKey(entityIdValStr))))
    targetLeadId.add(client.getObjectFactory().newPrimitiveProperty("@odata.type",
            client.getObjectFactory().newPrimitiveValueBuilder().buildString("#Microsoft.Dynamics.CRM.lead")))
    return targetLeadId
}
注意到:

funcReq.setFormatContentType.JSON_NO_元数据,用于指示发送到服务器的仅JSON格式。 从groovy到java,Intellij都有一个菜单项来实现这一点。也可以手动添加;大部分时间都是打字。
也许您想访问并检查是否可以对代码的格式进行任何改进。以当前的形式阅读和回答它是非常困难的;请点击编辑链接查看我做了什么来了解它是如何完成的