Skip to content

Type convert error in JsonPathSelector #129

Closed
@code4craft

Description

@code4craft

In JsonPathSelector, I just return Object object as a List when it is an instance of List. But actually it will return a net.minidev.json.JSONArray and it is an ArrayList. So when the user iterate the result, they will get an ClassCastException.

@Override
public List<String> selectList(String text) {
    List<String> list = new ArrayList<String>();
    Object object = jsonPath.read(text);
    if (object == null) {
        return list;
    }
    if (object instanceof List) {
        return (List<String>) object;
    } else {
        list.add(object.toString());
    }
    return list;
}

I just change it to

if (object instanceof List) {
    List<Object> items = (List<Object>) object;
    for (Object item : items) {
        list.add(String.valueOf(item));
    }
} else {

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions