net.minidev.json.actions.navigate.CopyPathsAction Maven / Gradle / Ivy
package net.minidev.json.actions.navigate;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.actions.path.TreePath;
import java.util.Collection;
import java.util.Stack;
/**
* Creates a copy of a {@link JSONObject} containing just the nodes on the paths specified.
*
* Specified paths that do not exist in the source object are ignored silently.
* Specifying an empty list of paths to navigate or only non-existent paths will result in an empty
* object being returned.
*
* See package-info for more details
*
* Example:
*
* To copy the branch k1.k2 from {k1:{k2:v1}, k3:{k4:v2}} instantiate the copier like so:
* new JSONObjectCopier("k1.k2")
* The resulting copy would be {k1:{k2:v1}}
*
* See unit tests for more examples
*
* @author [email protected]
* @since 15 March 2016.
*
*/
public class CopyPathsAction implements JSONNavigateAction {
protected JSONObject destTree;
protected JSONObject destBranch;
protected Stack