简体   繁体   English

Odata ClientEntity错误-预期的OData实体,找到了EntitySet

[英]Odata ClientEntity Error - Expected OData Entity, found EntitySet

I'm trying to use Olingo to connect to an Odata v4 service I've tested it with the Northwind sample and the URI that gets produce works in a browser: 我正在尝试使用Olingo连接到Odata v4服务,该服务已通过罗斯文(Northwind)示例进行了测试,并且可以在浏览器中获取产生的URI: I always get the following 我总是得到以下

error:java.lang.IllegalArgumentException:org.apache.olingo.commons.api.serialization.ODataDeserializerException:
com.fasterxml.jackson.core.JsonParseException: Expected OData Entity, found
EntitySet.

Code

ODataEntityRequest<ClientEntity> reqEntity = client.getRetrieveRequestFactory().getEntityRequest(entityURI);
                ODataRetrieveResponse<ClientEntity> entity = reqEntity.execute();
            ClientEntity ce = (ClientEntity)entity.getBody();

at last line i am getting error. 在最后一行,我得到了错误。

ClientEntity ce = (ClientEntity)entity.getBody();

This error means that you are querying a collection URL like http://services.odata.org/V4/Northwind/Northwind.svc/Categories . 此错误意味着您正在查询类似http://services.odata.org/V4/Northwind/Northwind.svc/Categories的集合URL。 The response for this is the EntitySet . 对此的响应是EntitySet

However, seems that you want a single Entity . 但是,似乎您想要一个Entity It can be got from the URL like http://services.odata.org/V4/Northwind/Northwind.svc/Categories(1) , where (1) corresponds with the ID of the Category you want to get. 可以从类似http://services.odata.org/V4/Northwind/Northwind.svc/Categories(1)的URL获得,其中(1)对应于您要获取的Category的ID。

2 options: 2种选择:

  • If you want a single Entity , create a proper URI, eg ODataClientFactory.getClient().newURIBuilder("http://services.odata.org/V4/Northwind/Northwind.svc").appendEntitySetSegment("Categories").appendKeySegment(1).build() and execute a request on this (I think you can even skip the casting thing) 如果需要单个Entity ,则创建一个适当的URI,例如ODataClientFactory.getClient().newURIBuilder("http://services.odata.org/V4/Northwind/Northwind.svc").appendEntitySetSegment("Categories").appendKeySegment(1).build()并对此执行请求(我认为您甚至可以跳过强制转换)
  • If you want EntitySet , go for getEntitySetRequest against your uri and then use getBody().getEntities() on the result of the execute() method 如果需要EntitySet ,请针对您的uri进行getEntitySetRequest ,然后在execute()方法的结果上使用getBody().getEntities()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM