带有花括号的Apache Olingo OData V4 ClientEntitySetIterator解析问题

时间:2019-03-13 19:43:04

标签: apache rest odata olingo odata-v4

我正在尝试通过使用Apache Olingo V4从API调用返回的客户端实体进行解析。我看到以下错误,当值字符串包含“ {”或“}”时,即使返回的数据为JSON格式,并且括号中都用引号引起来。

错误:

  

[main]:2019-03-13 13:52:21,719 ERROR JOID [] JNAME [] [ClientEntitySetIterator]-从EntitySet检索实体时出错   org.apache.olingo.client.api.serialization.ODataDeserializerException:com.fasterxml.jackson.core.JsonParseException:VALUE_STRING中意外的输入结束

代码

URIBuilder uriBuilder = client.newURIBuilder(url).appendEntitySetSegment("Orders");
    uriBuilder.addCustomQueryOption("$filter", filter.toString());
    uriBuilder.addCustomQueryOption("exported", "false");
    uriBuilder.addCustomQueryOption("$count", "true");
    URI absoluteUri = uriBuilder.build();

    ODataEntitySetIteratorRequest<ClientEntitySet, ClientEntity> request = 
            client.getRetrieveRequestFactory().getEntitySetIteratorRequest(absoluteUri);
    request.addCustomHeader(HttpHeader.AUTHORIZATION, "Bearer "+token);
    request.addCustomHeader("exported", "false");
    request.setFormat(ContentType.APPLICATION_JSON);
    request.setAccept("application/json;odata.metadata=minimal");

    ODataRetrieveResponse<ClientEntitySetIterator<ClientEntitySet, ClientEntity>> response = request.execute();

    int res = response.getStatusCode();
    String message = response.getStatusMessage();

    ClientEntitySetIterator<ClientEntitySet, ClientEntity>  iterator = response.getBody();

    while(iterator.hasNext()) {
        ClientEntity ce = iterator.next();
        ClientEntityImpl impl = (ClientEntityImpl) ce;
        String shippingStatus = impl.getProperty(SHIPPINGSTATUS).getValue().toString();
        String checkoutStatus = impl.getProperty(CHECKOUTSTATUS).getValue().toString();
        String paymentStatus = impl.getProperty(PAYMENTSTATUS).getValue().toString();
    }

如果返回的订单在value语句中包含“ {”或“}”,则在while循环开始时在iterator.hasNext()位置抛出错误。如果发生这种情况,即使剩余实体在value语句中不包含括号,也不会处理。有没有一种方法可以不使用ODataRetrieveResponse迭代器来处理该实体,或者跳过该实体并处理所有剩余实体?

0 个答案:

没有答案