0

when using the below code using XML it works perfectly, that is, the navigation links are returned successfully. However, when I change the format to "json" or "application/json", the links2 navigation links list is empty, meaning that rental.getNavigations() returns an empty list.

Can anyone help please? I am using Apache Olingo for Java OData v4.

Thanks

URI uri = client.newURIBuilder(serviceRoot)
                 .appendEntitySetSegment("Rentals")
                 .appendKeySegment(1).format("application/xml").build();

ODataRetrieveResponse<ODataEntity> response2 = client.getRetrieveRequestFactory().getEntityRequest(uri).execute();
ODataEntity rental = response2.getBody();

        List<ODataLink> links2 = rental.getNavigationLinks();
        for (ODataLink link : links2) {
            System.out.println(link.getRel());
            System.out.println(link.getName());
            URI linkUri = client.newURIBuilder(serviceRoot)
                      .appendNavigationSegment(link.getLink().toString()).format("atom").build();
            ODataRetrieveResponse<ODataEntity> responseCustomer
                    = client.getRetrieveRequestFactory().getEntityRequest(linkUri).execute();
            ODataEntity cust = responseCustomer.getBody();
            if(link.getName().equals("Stock"))
                System.out.println(cust.getProperty("Status").getValue().toString()); 
            else System.out.println(cust.getProperty("Name").getValue().toString()); 
       } 
user3423878
  • 51
  • 2
  • 8
  • Hi @user3423878. If my answer below has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – lencharest Mar 11 '16 at 22:11
  • When adding the odata.metadata=full format option, the OData service outputs an exception message which states that the service does not accept metadata=full format. Any ideas? Thanks – user3423878 Mar 16 '16 at 21:40
  • What is the exact error message? – lencharest Mar 16 '16 at 22:55

1 Answers1

1

The odata.metadata=full format parameter is necessary to get odata.navigationLink properties to appear in the JSON response. Add odata.metadata=full to the format option when building the client. The full format should be application/json;odata.metadata=full. If you have access to the request headers via the client object, you might consider setting the Accept header instead.

lencharest
  • 2,825
  • 2
  • 15
  • 22