All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minidev.json.actions.traverse.RemovePathsJsonAction Maven / Gradle / Ivy

package net.minidev.json.actions.traverse;

import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;

import java.util.List;
import java.util.Map.Entry;

/**
 * Removes branches from a {@link JSONObject}.
 * 

* A path is not removed from the user-specified list once its processing is over, * because identical objects in the same array are supported by this action. *

* See package-info for more details *

* See unit tests for examples * * @author [email protected] * */ public class RemovePathsJsonAction implements JSONTraverseAction { protected JSONObject result; protected List pathsToRemove; public RemovePathsJsonAction(List pathsToRemove) { this.pathsToRemove = pathsToRemove; } @Override public boolean start(JSONObject object) { result = object; return object != null && pathsToRemove != null && pathsToRemove.size() > 0; } @Override public boolean removeEntry(String fullPathToEntry, Entry entry) { return pathsToRemove.contains(fullPathToEntry); } @Override public boolean traverseEntry(String fullPathToEntry, Entry entry) { // must traverse the whole object return true; } @Override public boolean recurInto(String pathToEntry, JSONObject entryValue) { return true; } @Override public boolean recurInto(String pathToEntry, JSONArray entryValue) { return true; } @Override public void handleLeaf(String pathToEntry, Entry entry) { } @Override public void handleLeaf(String fullPathToContainingList, int listIndex, Object listItem) { } @Override public void end() { // nothing to do } @Override public Object result() { return result; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy