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: 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 . The response for this is the EntitySet .
However, seems that you want a single 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.
2 options:
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) getEntitySetRequest
against your uri and then use getBody().getEntities()
on the result of the execute()
method
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.