使用 Olingo v2 Java 作为 PATCH 到 OData v2 服务的客户端
Using Olingo v2 Java as client for PATCH to OData v2 service
我正在尝试使用 Olingo 来提供与 OData 服务交互的客户端(也是用 Olingo 编写的)。我正在尝试发送 PATCH。但是,标准验证例程正在启动,如果我不包括那些使用标准 Olingo 工具标记为不可为空的实体元素,我会收到错误消息。
在 https://olingo.apache.org/doc/odata2/tutorials/OlingoV2BasicClientSample.html 中说:
With an HTTP MERGE/PATCH it is also possible to send only the to be updated data as POST Body and omitting the unchanged data. But this is (currently) not shown within this sample.
不幸的是,我不知道该怎么做,那里似乎没有任何地方可以标记 EntityProvider.writeEntry 方法,它是 PATCH 而不是 POST/PUT
EntityProviderWriteProperties properties = EntityProviderWriteProperties
.serviceRoot(rootUri).omitJsonWrapper(true).contentOnly(true)
.build();
// serialize data into ODataResponse object
ODataResponse response = EntityProvider.writeEntry(contentType,
entitySet, data, properties);
此时,如果 "data" 不包含我的不可空字段的条目,我的代码会收到错误消息。对于不在我的 "data".
中的实体的所有属性,响应还 returns 空值
我通过操纵响应删除 "standard" 代之后不在我的 "data" 中的所有条目来处理这个问题,但想像一定有更好的方法,即使我做不到看见。关于如何处理这个的任何建议?
您必须创建一个 "ExpandSelectTreeNode",其中仅包含要序列化的选定属性的名称。
假设您的数据是一个具有值的 HashMap,您可以使用以下代码作为示例开始:
// data = new HashMap<>();
ExpandSelectTreeNode node = ExpandSelectTreeNode.entitySet(entitySet)
.selectedProperties(new ArrayList<String>(data.keySet())).build();
EntityProviderWriteProperties properties = EntityProviderWriteProperties
.serviceRoot(rootUri).omitJsonWrapper(true).contentOnly(true)
.expandSelectTree(node)
.build();
// serialize data into ODataResponse object
ODataResponse response = EntityProvider.writeEntry(contentType,
entitySet, data, properties);
此致
contenttype来自客户端application/json-patch+json ?
我正在尝试使用 Olingo 来提供与 OData 服务交互的客户端(也是用 Olingo 编写的)。我正在尝试发送 PATCH。但是,标准验证例程正在启动,如果我不包括那些使用标准 Olingo 工具标记为不可为空的实体元素,我会收到错误消息。
在 https://olingo.apache.org/doc/odata2/tutorials/OlingoV2BasicClientSample.html 中说:
With an HTTP MERGE/PATCH it is also possible to send only the to be updated data as POST Body and omitting the unchanged data. But this is (currently) not shown within this sample.
不幸的是,我不知道该怎么做,那里似乎没有任何地方可以标记 EntityProvider.writeEntry 方法,它是 PATCH 而不是 POST/PUT
EntityProviderWriteProperties properties = EntityProviderWriteProperties
.serviceRoot(rootUri).omitJsonWrapper(true).contentOnly(true)
.build();
// serialize data into ODataResponse object
ODataResponse response = EntityProvider.writeEntry(contentType,
entitySet, data, properties);
此时,如果 "data" 不包含我的不可空字段的条目,我的代码会收到错误消息。对于不在我的 "data".
中的实体的所有属性,响应还 returns 空值我通过操纵响应删除 "standard" 代之后不在我的 "data" 中的所有条目来处理这个问题,但想像一定有更好的方法,即使我做不到看见。关于如何处理这个的任何建议?
您必须创建一个 "ExpandSelectTreeNode",其中仅包含要序列化的选定属性的名称。 假设您的数据是一个具有值的 HashMap,您可以使用以下代码作为示例开始:
// data = new HashMap<>();
ExpandSelectTreeNode node = ExpandSelectTreeNode.entitySet(entitySet)
.selectedProperties(new ArrayList<String>(data.keySet())).build();
EntityProviderWriteProperties properties = EntityProviderWriteProperties
.serviceRoot(rootUri).omitJsonWrapper(true).contentOnly(true)
.expandSelectTree(node)
.build();
// serialize data into ODataResponse object
ODataResponse response = EntityProvider.writeEntry(contentType,
entitySet, data, properties);
此致
contenttype来自客户端application/json-patch+json ?