다른 JSON 객체를 필터로 사용하여 특정 JSON 파일을 필터링 할 수있는 기능이 있습니다.배열의 일부를 포함하는 JSON 파일에 대한 필터
참조 코드 : 내가 할 노력하고있어
{
"objects": [
"object1",
"object2"
],
}
배열 오브젝트는 오브젝트 1 포함 된 모든 파일을 필터링 할 수 있습니다 :
public Map<String, Entry<JsonObject, Long>> loadFilter(Coll<?> coll, JsonObject filter){
// Create Ret
Map<String, Entry<JsonObject, Long>> ret = null;
// Get Directory
File directory = getDirectory(coll);
if (! directory.isDirectory()) return ret;
// Find All
File[] files = directory.listFiles(JsonFileFilter.get());
// Create Ret
ret = new LinkedHashMap<String, Entry<JsonObject, Long>>(files.length);
// Filter rules
Set<Map.Entry<String, JsonElement>> filterRules = filter.entrySet();
// For Each Found
for (File file : files)
{
// Get ID
String id = idFromFile(file);
// Get Entry
Entry<JsonObject, Long> entry = loadFile(file);
// Trying to fix a weird condition causing a NPE error
if(entry == null) continue;
if(entry.getKey() == null) continue;
// Compare the files with the given filter
Set<Map.Entry<String, JsonElement>> fileEntries = entry.getKey().entrySet();
if (fileEntries.containsAll(filterRules)) {
// Add found data to return list
ret.put(id, entry);
}
}
return ret;
}
나는 다음과 같은 JSON을 상상해보십시오. 나는 객체 2에 대해 신경 쓰지 않는다. 적어도 객체 배열에있는 객체 1을 가진 파일들을 필터링하고 싶다.
아무것도 결과 아래의 코드 :
JsonObject filter = new JsonObject();
JsonArray array = new JsonArray();
array.add(new JsonPrimitive("object1"));
filter.add("objects", array);
Map<String, Entry<JsonObject, Long>> result = loadFilter(coll, filter); // nothing
어떤 도움이 appriciated됩니다.
늦게 응답 해 주셔서 감사합니다. 나는 기본적으로 전체 필터에있는 배열을이 함수에 넣을 것입니다. –
'predicate'은 배열 인 여러 필드를 가진'JsonObject' 일 수 있습니다. – izstas