0

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();
toha
  • 5,095
  • 4
  • 40
  • 52
Sandip Bhot
  • 53
  • 1
  • 7
  • Refer below link https://stackoverflow.com/questions/35297844/how-can-i-consume-an-odata4-service-in-java-using-either-olingo-or-the-sdl-odata – Sandip Bhot Jul 13 '17 at 09:05

1 Answers1

0

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:

  • If you want a single Entity, create a proper URI, e.g. 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)
  • If you want EntitySet, go for getEntitySetRequest against your uri and then use getBody().getEntities() on the result of the execute() method
mat3e
  • 781
  • 5
  • 17