Browse Source

use the json provider to create a new list for the results

pull/22/head
Jochen Berger 12 years ago
parent
commit
7c84838239
  1. 7
      json-path/src/main/java/com/jayway/jsonpath/Filter.java
  2. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/filter/ArrayQueryFilter.java

7
json-path/src/main/java/com/jayway/jsonpath/Filter.java

@ -16,6 +16,8 @@ package com.jayway.jsonpath;
import java.util.*; import java.util.*;
import com.jayway.jsonpath.spi.JsonProvider;
/** /**
* A filter is used to filter the content of a JSON array in a JSONPath. * A filter is used to filter the content of a JSON array in a JSONPath.
* *
@ -45,10 +47,11 @@ public abstract class Filter<T> {
/** /**
* Filters the provided list based on this filter configuration * Filters the provided list based on this filter configuration
* @param filterItems items to filter * @param filterItems items to filter
* @param jsonProvider the json provider that is used to create the result list
* @return the filtered list * @return the filtered list
*/ */
public List<T> doFilter(List<T> filterItems) { public List doFilter(List<T> filterItems, JsonProvider jsonProvider) {
List<T> result = new ArrayList<T>(); List result = jsonProvider.createList();;
for (T filterItem : filterItems) { for (T filterItem : filterItems) {
if (accept(filterItem)) { if (accept(filterItem)) {
result.add(filterItem); result.add(filterItem);

2
json-path/src/main/java/com/jayway/jsonpath/internal/filter/ArrayQueryFilter.java

@ -34,7 +34,7 @@ public class ArrayQueryFilter extends PathTokenFilter {
Filter filter = filters.poll(); Filter filter = filters.poll();
return filter.doFilter((List)obj); return filter.doFilter((List)obj, jsonProvider);
} }

Loading…
Cancel
Save