Class CopyPathsAction
java.lang.Object
net.minidev.json.actions.navigate.CopyPathsAction
- All Implemented Interfaces:
JSONNavigateAction,NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
Creates a copy of a
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
- Since:
- 15 March 2016.
- Author:
- adoneitan@gmail.com
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected net.minidev.json.JSONObjectprotected net.minidev.json.JSONObject -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidend()called after all navigation ends, and just before the navigation method exitsbooleancalled if navigation of a path throws an exceptionbooleanfailSilently(String path, Exception e) called if navigation of a path throws an exceptionvoidfoundLeafBeforePathEnd(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 sourcevoidhandleLeaf(TreePath jp, int arrIndex, Object o) called when a leaf in a L is reached.voidhandleLeaf(TreePath jp, Object o) called when a leaf node is reached in a M.voidcalled after the navigation of a path endsbooleancalled before navigation of a new path startsvoidpathTailNotFound(TreePath jp, Object source) reached end of branch in source before end of specified path - the specified path does not exist in the sourcevoidcalled when navigation of anNavigateActiontype object endsvoidcalled when navigation of anNavigateActiontype object endsbooleancalled when an array node is encountered on the pathbooleancalled when an object node is encountered on the pathresult()holds the result of the navigation, as assigned by the action implementing this interfacebooleanstart(net.minidev.json.JSONObject source, Collection<String> pathsToCopy) called before any navigation of theNavigateActionstarts
-
Field Details
-
destTree
protected net.minidev.json.JSONObject destTree -
destBranch
protected net.minidev.json.JSONObject destBranch -
destNodeStack
-
-
Constructor Details
-
CopyPathsAction
public CopyPathsAction()
-
-
Method Details
-
start
Description copied from interface:NavigateActioncalled before any navigation of theNavigateActionstarts- Specified by:
startin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
source- TODOpathsToCopy- TODO- Returns:
- true if navigation should start at all
-
recurInto
Description copied from interface:NavigateActioncalled when an object node is encountered on the path- Specified by:
recurIntoin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
jp- TODOo- TODO- Returns:
- true if the navigator should navigate into the object
-
recurInto
Description copied from interface:NavigateActioncalled when an array node is encountered on the path- Specified by:
recurIntoin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
jp- TODOo- TODO- Returns:
- true if the navigator should navigate into the array
-
foundLeafBeforePathEnd
Description copied from interface:NavigateActionreached leaf node (not a container) in source but specified path expects children - the specified path does not exist in the source- Specified by:
foundLeafBeforePathEndin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
jp- TODOobj- TODO
-
pathTailNotFound
Description copied from interface:NavigateActionreached end of branch in source before end of specified path - the specified path does not exist in the source- Specified by:
pathTailNotFoundin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
jp- TODOsource- TODO
-
handleLeaf
Description copied from interface:NavigateActioncalled when a leaf node is reached in a M. a leaf in a M is a key-value pair where the value is not a container itself (it is not a M nor a L)- Specified by:
handleLeafin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
jp- - the JsonPath pointing to the leafo- TODO
-
handleLeaf
Description copied from interface:NavigateActioncalled when a leaf in a L is reached. a leaf in a L is a non-container item (it is not a M nor a L)- Specified by:
handleLeafin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
jp- -arrIndex- -o- - the item
-
recurEnd
Description copied from interface:NavigateActioncalled when navigation of anNavigateActiontype object ends- Specified by:
recurEndin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
jp- the path pointing to the objectjo- TODO
-
recurEnd
Description copied from interface:NavigateActioncalled when navigation of anNavigateActiontype object ends- Specified by:
recurEndin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
jp- the path pointing to the objectja- TODO
-
pathStart
Description copied from interface:NavigateActioncalled before navigation of a new path starts- Specified by:
pathStartin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
path- TODO- Returns:
- true if the specified path should be navigated
-
pathEnd
Description copied from interface:NavigateActioncalled after the navigation of a path ends- Specified by:
pathEndin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
path- TODO
-
failSilently
Description copied from interface:NavigateActioncalled if navigation of a path throws an exception- Specified by:
failSilentlyin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
path- TODOe- TODO- Returns:
- true if the failure on this path should not abort the rest of the navigation
-
failFast
Description copied from interface:NavigateActioncalled if navigation of a path throws an exception- Specified by:
failFastin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Parameters:
path- TODOe- TODO- Returns:
- true if the failure on this path should abort the rest of the navigation
-
end
public void end()Description copied from interface:NavigateActioncalled after all navigation ends, and just before the navigation method exits- Specified by:
endin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
-
result
Description copied from interface:NavigateActionholds the result of the navigation, as assigned by the action implementing this interface- Specified by:
resultin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray> - Returns:
- - result
-