public class CopyPathsAction extends Object implements JSONNavigateAction
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
Modifier and Type | Field and Description |
---|---|
protected net.minidev.json.JSONObject |
destBranch |
protected Stack<Object> |
destNodeStack |
protected net.minidev.json.JSONObject |
destTree |
Constructor and Description |
---|
CopyPathsAction() |
Modifier and Type | Method and Description |
---|---|
void |
end()
called after all navigation ends, and just before the navigation method exits
|
boolean |
failFast(String path,
Exception e)
called if navigation of a path throws an exception
|
boolean |
failSilently(String path,
Exception e)
called if navigation of a path throws an exception
|
void |
foundLeafBeforePathEnd(TreePath jp,
Object obj)
reached leaf node (not a container) in source but specified path expects children -
the specified path does not exist in the source
|
void |
handleLeaf(TreePath jp,
int arrIndex,
Object o)
called when a leaf in a L is reached.
|
void |
handleLeaf(TreePath jp,
Object o)
called when a leaf node is reached in a M.
|
void |
pathEnd(String path)
called after the navigation of a path ends
|
boolean |
pathStart(String path)
called before navigation of a new path starts
|
void |
pathTailNotFound(TreePath jp,
Object source)
reached end of branch in source before end of specified path -
the specified path does not exist in the source
|
void |
recurEnd(TreePath jp,
net.minidev.json.JSONArray ja)
called when navigation of an
L type object ends |
void |
recurEnd(TreePath jp,
net.minidev.json.JSONObject jo)
called when navigation of an
M type object ends |
boolean |
recurInto(TreePath jp,
net.minidev.json.JSONArray o)
called when an array node is encountered on the path
|
boolean |
recurInto(TreePath jp,
net.minidev.json.JSONObject o)
called when an object node is encountered on the path
|
Object |
result()
holds the result of the navigation, as assigned by the action implementing this interface
|
boolean |
start(net.minidev.json.JSONObject source,
Collection<String> pathsToCopy)
called before any navigation of the
M starts |
protected net.minidev.json.JSONObject destTree
protected net.minidev.json.JSONObject destBranch
public boolean start(net.minidev.json.JSONObject source, Collection<String> pathsToCopy)
NavigateAction
M
startsstart
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public boolean recurInto(TreePath jp, net.minidev.json.JSONObject o)
NavigateAction
recurInto
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public boolean recurInto(TreePath jp, net.minidev.json.JSONArray o)
NavigateAction
recurInto
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public void foundLeafBeforePathEnd(TreePath jp, Object obj)
NavigateAction
foundLeafBeforePathEnd
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public void pathTailNotFound(TreePath jp, Object source)
NavigateAction
pathTailNotFound
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public void handleLeaf(TreePath jp, Object o)
NavigateAction
handleLeaf
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
jp
- - the JsonPath pointing to the leafpublic void handleLeaf(TreePath jp, int arrIndex, Object o)
NavigateAction
handleLeaf
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
arrIndex
- - the index of the item in the Lo
- - the itempublic void recurEnd(TreePath jp, net.minidev.json.JSONObject jo)
NavigateAction
M
type object endsrecurEnd
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
jp
- the path pointing to the objectpublic void recurEnd(TreePath jp, net.minidev.json.JSONArray ja)
NavigateAction
L
type object endsrecurEnd
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
jp
- the path pointing to the objectpublic boolean pathStart(String path)
NavigateAction
pathStart
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public void pathEnd(String path)
NavigateAction
pathEnd
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public boolean failSilently(String path, Exception e)
NavigateAction
failSilently
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public boolean failFast(String path, Exception e)
NavigateAction
failFast
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public void end()
NavigateAction
end
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public Object result()
NavigateAction
result
in interface NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
Copyright © 2020 Chemouni Uriel. All rights reserved.