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

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

Go to download

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

There is a newer version: 2.5.1
Show newest version
package net.minidev.json.actions.traverse;

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

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

/**
 * Removes key:value elements from a {@link JSONObject}.
 * 

* An element is not removed from the user-specified list once its processing is over, * because it may appear in more than one node. *

* See package-info for more details *

* See unit tests for examples * * @author [email protected] * */ public class RemoveElementsJsonAction implements JSONTraverseAction { protected JSONObject result; protected final Map elementsToRemove; protected final boolean allowDotChar; public RemoveElementsJsonAction(Map elementsToRemove, boolean allowDotChar) { this.elementsToRemove = elementsToRemove; this.allowDotChar = allowDotChar; } public RemoveElementsJsonAction(Map elementsToRemove) { this(elementsToRemove, false); } @Override public boolean start(JSONObject object) { result = object; return object != null && elementsToRemove != null && elementsToRemove.size() > 0; } @Override public boolean removeEntry(String fullPathToEntry, Entry entry) { return elementsToRemove.entrySet().contains(entry); } @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