Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
82d83fe
Added few handy methods (smth like "builder pattern").
kirilldev Jan 2, 2016
1a0cf3e
introduce helper classes to process a JSONObject and its nodes
erav Apr 5, 2016
2d42e34
gitignore intellij idea files
erav Apr 5, 2016
909c53c
rename actions
erav Apr 17, 2016
38f9a53
add ElementRemover
erav Apr 17, 2016
92adc26
enhance traversal API
erav Jun 6, 2016
4de36a4
support any delimiter in traverser
erav Jun 7, 2016
efb8714
simplif api
erav Jun 8, 2016
5391eff
create tree navigator
erav Jun 19, 2016
1649130
house cleaning
erav Jun 19, 2016
ad93cc5
finalize tree navigator
erav Jun 21, 2016
8745243
Merge pull request #24 from erav/master
UrielCh Sep 24, 2016
5c3baae
Setp 1 unify code format + fix invalide java filename
UrielCh Sep 24, 2016
83e8aea
remove executable flad on java files
UrielCh Sep 24, 2016
7447287
reformat
UrielCh Sep 24, 2016
6eb2670
make test unit more readable
UrielCh Sep 24, 2016
eacbfb9
smal improvement
UrielCh Sep 24, 2016
b5c2da1
move action to json-smart-action
UrielCh Sep 24, 2016
9bd4b28
fix pom error
UrielCh Sep 24, 2016
1a11a47
change version and timeZone in pom
UrielCh Sep 24, 2016
d44241c
Merge pull request #31 from netplex/erav
UrielCh Sep 24, 2016
8aa02c8
Merge remote-tracking branch 'origin/v2.3' into pr/21
UrielCh Sep 24, 2016
dc4fbfb
Merge pull request #32 from netplex/pr/21
UrielCh Sep 24, 2016
6ba8c86
Remove the inlined ASM dependency in smart-accessors
mattnelson Oct 21, 2016
d4844f2
Merge pull request #35 from mattnelson/master
UrielCh Nov 3, 2016
ecf46cd
retro merge (@_@)'
UrielCh Mar 25, 2017
404baea
update README
UrielCh Mar 25, 2017
8653fa0
fix issue 33
UrielCh Mar 25, 2017
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ json-smart/target/
*.classpath
*.project
*.prefs
*.iml
.idea
2 changes: 1 addition & 1 deletion accessors-smart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<id>uriel</id>
<name>Uriel Chemouni</name>
<email>uchemouni@gmail.com</email>
<timezone>GMT+1</timezone>
<timezone>GMT-7</timezone>
<roles>
</roles>
</developer>
Expand Down
1 change: 1 addition & 0 deletions json-smart-action/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
259 changes: 259 additions & 0 deletions json-smart-action/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- this POM is released under an Apache 2.0 license -->
<parent>
<groupId>net.minidev</groupId>
<artifactId>minidev-parent</artifactId>
<version>2.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>json-smart-action</artifactId>
<name>JSON Small and Fast Parser</name>
<description>
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.
</description>
<packaging>bundle</packaging>
<url>http://www.minidev.net/</url>
<organization>
<name>Chemouni Uriel</name>
<url>http://www.minidev.net/</url>
</organization>
<developers>
<developer>
<id>uriel</id>
<name>Uriel Chemouni</name>
<email>uchemouni@gmail.com</email>
<timezone>GMT-7</timezone>
<roles>
</roles>
</developer>
<developer>
<id>erav</id>
<name>Eitan Raviv</name>
<email>adoneitan@gmail.com</email>
<timezone>GMT+2</timezone>
</developer>
</developers>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>All files under Apache 2</comments>
</license>
</licenses>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
</dependency>
</dependencies>
<scm>
<!-- ON GIT HUB -->
<connection>scm:git:https://github.com/netplex/json-smart-v2.git</connection>
<developerConnection>scm:git:https://github.com/netplex/json-smart-v2.git</developerConnection>
<url>https://github.com/netplex/json-smart-v2</url>
</scm>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<profiles>
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<!-- will be set by the release plugin upon performing mvn release:perform -->
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<properties>
<!-- My old Is back -->
<gpg.keyname>2C8DF6EC</gpg.keyname>
<!-- <gpg.keyname>8E322ED0</gpg.keyname> -->
<!-- <gpg.keyname>Uriel Chemouni (dev) <uchemouni@gmail.com></gpg.keyname> -->
<!-- GPG Key ID to use for signing -->
</properties>
<build>
<plugins>
<!-- Enable signing of the artifacts For gpg:sign-and-deploy-file it's
necessary to have a <server> with the repositoryId provided or id="remote-repository"
defined in settings.xml (it contains the repository's login, psw) Signing:
mvn gpg:sign-and-deploy-file -DpomFile=target/myapp-1.0.pom -Dfile=target/myapp-1.0.jar
-Durl=http://oss.sonatype.org/content/repositories/malyvelky/ -DrepositoryId=sonatype_oss
Note normally it uses the defaul key but we can ovveride it by either setting
the property gpg.keyname (done in this POM) or by providing -Dkeyname=66AE163A
on the command line. OR directly w/ gpg (remove space in - -): gpg -u 66AE163A
- -sign - -detach-sign -a target/dbunit-embeddedderby-parenttest.jar Note:
"mvn gpg:sign" results in NPE with v 1.o-a.-4, use "mvn package gpg:sign"
instead; see the issue MGPG-18 -->
<plugin>
<!-- updated on 29/07/2015 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Publish also javadocs when releasing - required by Sonatype -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Release Plugin (Update version in POM before/after release, create
tag, deploy) to try: mvn release:prepare -DdryRun=true && mvn release:clean
to perform: mvn release:prepare release:perform Read http://nexus.sonatype.org/oss-repository-hosting.html#3
for instructions on releasing to this project's Sonatype repository -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<mavenExecutorId>forked-path</mavenExecutorId>
<arguments>-Psonatype-oss-release</arguments>
<autoVersionSubmodules>false</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>include-sources</id>
<build>
<resources>
<resource>
<targetPath>/</targetPath>
<filtering>true</filtering>
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<!-- updated on 29/07/2015 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>bind-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- updated on 29/10/2015 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
<excludes>
<exclude>**/.svn/*</exclude>
<exclude>**/.svn</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<!-- updated on 29/10/2015 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<!-- updated on 29/10/2015 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<excludes>
<exclude>**/.svn/*</exclude>
<exclude>**/.svn</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<!-- updated on 29/07/2015 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<!-- ONLY NEEDED With jdk 1.7+ -->
<configuration>
<failOnError>false</failOnError>
<!-- <additionalparam>-Xdoclint:none</additionalparam> -->
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.0.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package>
net.minidev.json, net.minidev.json.annotate, net.minidev.json.parser, net.minidev.json.reader, net.minidev.json.writer
</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.minidev.json.actions;

import net.minidev.json.JSONObject;
import net.minidev.json.actions.traverse.JSONTraverser;
import net.minidev.json.actions.traverse.RemoveElementsJsonAction;
import net.minidev.json.actions.traverse.JSONTraverseAction;

import java.util.*;

/**
* <b>Removes key:value elements from every node of a {@link JSONObject} matching the list of user-specified elements.</b>
* <p>
* An element to remove must be specified as a key:value pair
* <p>
* <b>Usage Example:</b>
* <p>
* To remove the element k2:v2 from the {@link JSONObject} {k0:{k2:v2, k3:v3}, k1:{k2:v2, k4:v4}} use the remover like so:
* <pre>
* PathRemover pr = new PathRemover("k2.v2");
* JSONObject cleanObject = pr.remove(new JSONObject(...));
* </pre>
* The resulting object 'cleanObject' would be {k0:{k3:v3}, k1:{k4:v4}}
* <p>
* See unit tests for more examples
*
* @author adoneitan@gmail.com
*
*/
public class ElementRemover {
private Map<String, Object> elementsToRemove;

public ElementRemover(Map<String, Object> elementsToRemove) {
this.elementsToRemove = elementsToRemove == null ? Collections.<String, Object> emptyMap() : elementsToRemove;
}

public ElementRemover(JSONObject elementsToRemove) {
this.elementsToRemove = elementsToRemove == null ? Collections.<String, Object> emptyMap() : elementsToRemove;
}

public JSONObject remove(JSONObject objectToClean) {
JSONTraverseAction strategy = new RemoveElementsJsonAction(this.elementsToRemove);
JSONTraverser traversal = new JSONTraverser(strategy);
traversal.traverse(objectToClean);
return (JSONObject) strategy.result();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package net.minidev.json.actions;

import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.actions.path.DotDelimiter;
import net.minidev.json.actions.path.PathDelimiter;
import net.minidev.json.actions.traverse.JSONTraverser;
import net.minidev.json.actions.traverse.LocatePathsJsonAction;
import net.minidev.json.actions.traverse.JSONTraverseAction;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
* <b>Searches for paths in a {@link JSONObject} and returns those found.</b>
* <p>
* Traverses the specified {@link JSONObject} searching for nodes whose paths (from the root down) match
* any of the user-specified paths. The paths that match are returned.
* <p>
* A path to locate must be specified in the n-gram format - a list of keys from the root down separated by dots:
* K0[[[[.K1].K2].K3]...]
* <br>
* 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.
* <p>
*
* @author adoneitan@gmail.com
*/
public class PathLocator {
protected List<String> pathsToFind;
protected PathDelimiter pathDelimiter = new DotDelimiter().withAcceptDelimiterInNodeName(false);

public PathLocator(JSONArray pathsToFind) {
if (pathsToFind == null || pathsToFind.isEmpty()) {
this.pathsToFind = Collections.emptyList();
} else {
this.pathsToFind = new ArrayList<String>();
for (Object s : pathsToFind) {
this.pathsToFind.add((String) s);
}
}
}

public PathLocator(List<String> pathsToFind) {
this.pathsToFind = pathsToFind == null || pathsToFind.size() == 0 ? Collections.<String> emptyList() : pathsToFind;
}

public PathLocator(String... pathsToFind) {
this.pathsToFind = pathsToFind == null || pathsToFind.length == 0 ? Collections.<String> emptyList() : Arrays.asList(pathsToFind);
}

public PathLocator with(PathDelimiter pathDelimiter) {
this.pathDelimiter = pathDelimiter;
return this;
}

public List<String> locate(JSONObject object) {
JSONTraverseAction action = new LocatePathsJsonAction(this.pathsToFind, pathDelimiter);
JSONTraverser traversal = new JSONTraverser(action).with(pathDelimiter);
traversal.traverse(object);
return (List<String>) action.result();
}
}
Loading