Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
matt-carr opened this issue Feb 19, 2020 · 1 comment
Open

Comments

@matt-carr
Copy link

matt-carr commented Feb 19, 2020

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();
@bdmogal
Copy link
Contributor

bdmogal commented Apr 17, 2020

@matt-carr thanks for reporting this. It didn't get the required attention because we track issues at https://issues.cask.co/. There's already an open bug for this - https://issues.cask.co/browse/PLUGIN-123.

Feel free to open a PR with this if you'd like to. We'd welcome the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants