Skip to content

JSON Parser can't handle the root of the response being a JSON List #29

Description

@matt-carr

new JSONPages try to parse the response entity as a JSON object rather than as arbitrary JSON

could solve sorta like:

   super(httpResponse);
    this.config = config;
    JsonElement jsonElement = JsonParser.parse(httpResponse.getBody());
    if(!json.isJsonArray()) {
        json = jsonElement.toJsonElement();
       JSONUtil.JsonQueryResponse queryResponse = JSONUtil.getJsonElementByPath(json, config.getResultPath());
       insideElementJsonPathPart = queryResponse.getUnretrievedPath();

      jsonElement = queryResponse.get();
    }
    if (jsonElement.isJsonArray()) {
      iterator = queryResponse.getAsJsonArray().iterator();
    } else if (jsonElement.isJsonObject()) {
      iterator = Collections.singleton(jsonElement).iterator();
    } else {
      throw new IllegalArgumentException(String.format("Element found by '%s' json path is expected to be an object " +
                                                         "or an array. Primitive found", config.getResultPath()));
    }

    fieldsMapping = config.getFullFieldsMapping();
    schema = config.getSchema();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions