Package net.minidev.json.actions
Class PathReplicator
- java.lang.Object
-
- net.minidev.json.actions.PathReplicator
-
public class PathReplicator extends Object
Creates a copy of aJSONObjectconsisting only of the nodes on the user-specified paths.Paths that do not exist in the specified object are ignored silently. Specifying an empty list of paths to copy or only non-existent paths will result in an empty object being returned.
A path to copy must be specified in the n-gram format - a list of keys from the root down separated by dots: K0[[[[.K1].K2].K3]...]
A key to the right of a dot is a direct child of a key to the left of a dot. Keys with a dot in their name are not supported.Sample usage:
To replicate the branch k1.k2 from {k1:{k2:v2}, k3:{k4:v4}} use the
PathReplicatorlike so:PathReplicator pr = new
The resulting object 'copiedObject' would be {k1:{k2:v2}}PathReplicator("k1.k2") JSONObject copiedObject = pr.copy(new JSONObject(...))see unit tests for more examples
- Since:
- 15 March 2016.
- Author:
- adoneitan@gmail.com
-
-
Field Summary
Fields Modifier and Type Field Description protected List<String>pathsToCopy
-
Constructor Summary
Constructors Constructor Description PathReplicator(String... pathsToCopy)PathReplicator(List<String> pathsToCopy)PathReplicator(net.minidev.json.JSONArray pathsToCopy)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description net.minidev.json.JSONObjectreplicate(net.minidev.json.JSONObject sourceObj)
-