Skip to content

Added accessors for op and path in JsonPathOperation #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Its features are:

## Versions

The current version is **1.13**. See file `RELEASE-NOTES.md` for details.
The current version is **1.14**. See file `RELEASE-NOTES.md` for details.

## Using it in your project

Expand Down
4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.14

* Introduce "remove?" operation

## 1.13

* Introduce "translate" and "translate?" operations
Expand Down
148 changes: 74 additions & 74 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,47 @@
* - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt
*/

apply(plugin: "java");
apply(plugin: "maven");
apply(plugin: "signing");
apply(plugin: "osgi");
apply(plugin: "idea");
apply(plugin: "eclipse");

group = "com.box";
version = "1.14-SNAPSHOT";
sourceCompatibility = "1.6";
targetCompatibility = "1.6"; // defaults to sourceCompatibility
apply(plugin: "java")
apply(plugin: "maven")
apply(plugin: "signing")
apply(plugin: "osgi")
apply(plugin: "idea")
apply(plugin: "eclipse")

group = "com.box"
version = "1.15-SNAPSHOT"
sourceCompatibility = "1.6"
targetCompatibility = "1.6" // defaults to sourceCompatibility

/*
* List of dependencies
*/
dependencies {
compile(group: "com.google.code.findbugs", name: "jsr305", version: "2.0.1");
compile(group: "com.github.fge", name: "jackson-coreutils", version: "1.6");
compile(group: "com.google.code.findbugs", name: "jsr305", version: "2.0.1")
compile(group: "com.github.fge", name: "jackson-coreutils", version: "1.6")
testCompile(group: "org.testng", name: "testng", version: "6.8.7") {
exclude(group: "junit", module: "junit");
exclude(group: "org.beanshell", module: "bsh");
exclude(group: "org.yaml", module: "snakeyaml");
};
testCompile(group: "org.mockito", name: "mockito-core", version: "1.9.5");
testCompile(group: "org.assertj", name: "assertj-core", version: "1.7.0");
exclude(group: "junit", module: "junit")
exclude(group: "org.beanshell", module: "bsh")
exclude(group: "org.yaml", module: "snakeyaml")
}
testCompile(group: "org.mockito", name: "mockito-core", version: "1.9.5")
testCompile(group: "org.assertj", name: "assertj-core", version: "1.7.0")
}

javadoc.options.links("http://docs.oracle.com/javase/6/docs/api/");
javadoc.options.links("http://jsr-305.googlecode.com/svn/trunk/javadoc/");
javadoc.options.links("http://fasterxml.github.com/jackson-databind/javadoc/2.2.0/");
javadoc.options.links("http://fasterxml.github.com/jackson-core/javadoc/2.2.0/");
javadoc.options.links("http://fasterxml.github.com/jackson-annotations/javadoc/2.2.0/");
javadoc.options.links("http://docs.guava-libraries.googlecode.com/git-history/v16.0.1/javadoc/");
javadoc.options.links("http://fge.github.io/msg-simple/");
javadoc.options.links("http://fge.github.io/jackson-coreutils/");
javadoc.options.links("http://docs.oracle.com/javase/6/docs/api/")
javadoc.options.links("http://jsr-305.googlecode.com/svn/trunk/javadoc/")
javadoc.options.links("http://fasterxml.github.com/jackson-databind/javadoc/2.2.0/")
javadoc.options.links("http://fasterxml.github.com/jackson-core/javadoc/2.2.0/")
javadoc.options.links("http://fasterxml.github.com/jackson-annotations/javadoc/2.2.0/")
javadoc.options.links("http://docs.guava-libraries.googlecode.com/git-history/v16.0.1/javadoc/")
javadoc.options.links("http://fge.github.io/msg-simple/")
javadoc.options.links("http://fge.github.io/jackson-coreutils/")

/*
* Repositories to use
*/
repositories {
mavenCentral();
mavenCentral()
}

/*
Expand All @@ -66,16 +66,16 @@ repositories {
*/
test {
useTestNG() {
useDefaultListeners = true;
};
useDefaultListeners = true
}
}

/*
* Necessary to generate the source and javadoc jars
*/
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources";
from sourceSets.main.allSource;
classifier = "sources"
from sourceSets.main.allSource
}

/*
Expand All @@ -88,71 +88,71 @@ task sourcesJar(type: Jar, dependsOn: classes) {
//}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = "javadoc";
from javadoc.destinationDir;
classifier = "javadoc"
from javadoc.destinationDir
}

artifacts {
archives jar;
archives sourcesJar;
archives javadocJar;
archives jar
archives sourcesJar
archives javadocJar
}

task wrapper(type: Wrapper) {
gradleVersion = "2.5";
distributionUrl = "http://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip";
gradleVersion = "2.5"
distributionUrl = "http://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}

task pom << {
pom {}.writeTo("${projectDir}/pom.xml");
pom {}.writeTo("${projectDir}/pom.xml")
}

/*
* SIGNING
*/

project.ext {
description = "JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7386) implementation in Java";
scmURL = sprintf("[email protected]:box-metadata/%s.git", name);
projectURL = sprintf("https://github.com/box-metadata/%s", name);
sonatypeStaging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/";
sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots/";
};
description = "JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7386) implementation in Java"
scmURL = sprintf("[email protected]:box-metadata/%s.git", name)
projectURL = sprintf("https://github.com/box-metadata/%s", name)
sonatypeStaging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots/"
}

task checkSigningRequirements << {
def requiredProperties = [ "sonatypeUsername", "sonatypePassword" ];
def noDice = false;
def requiredProperties = [ "sonatypeUsername", "sonatypePassword" ]
def noDice = false
requiredProperties.each {
if (project.properties[it] == null) {
noDice = true;
noDice = true
System.err.printf("property \"%s\" is not defined!")
}
}
if (noDice)
throw new IllegalStateException("missing required properties for " +
"upload");
"upload")
}

uploadArchives {
dependsOn(checkSigningRequirements);
dependsOn(checkSigningRequirements)
repositories {
mavenDeployer {
beforeDeployment {
MavenDeployment deployment -> signing.signPom(deployment);
MavenDeployment deployment -> signing.signPom(deployment)
}

repository(url: "${sonatypeStaging}") {
authentication(
userName: project.properties["sonatypeUsername"],
password: project.properties["sonatypePassword"]
);
)
}

snapshotRepository(url: "${sonatypeSnapshots}") {
authentication(
userName: project.properties["sonatypeUsername"],
password: project.properties["sonatypePassword"]
);
)
}
}
}
Expand All @@ -166,43 +166,43 @@ uploadArchives {
uploadArchives.repositories.mavenDeployer
]*.pom*.whenConfigured { pom ->
pom.project {
name "${project.name}";
packaging "jar";
description "${project.ext.description}";
url "${projectURL}";
name "${project.name}"
packaging "jar"
description "${project.ext.description}"
url "${projectURL}"

scm {
url "${scmURL}";
connection "scm:git:${scmURL}";
developerConnection "scm:git${scmURL}";
url "${scmURL}"
connection "scm:git:${scmURL}"
developerConnection "scm:git${scmURL}"
}

licenses {
license {
name "Lesser General Public License, version 3 or greater";
url "http://www.gnu.org/licenses/lgpl.html";
distribution "repo";
};
name "Lesser General Public License, version 3 or greater"
url "http://www.gnu.org/licenses/lgpl.html"
distribution "repo"
}
license {
name "Apache Software License, version 2.0";
url "http://www.apache.org/licenses/LICENSE-2.0";
distribution "repo";
name "Apache Software License, version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0"
distribution "repo"
}
}

developers {
developer {
id "metadata-dev";
name "Metadata Dev";
email "[email protected]";
id "metadata-dev"
name "Metadata Dev"
email "[email protected]"
}
}
}
}

ext.forRelease = !version.endsWith("-SNAPSHOT");
ext.forRelease = !version.endsWith("-SNAPSHOT")
signing {
required { forRelease && gradle.taskGraph.hasTask("uploadArchives") };
sign configurations.archives;
required { forRelease && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static JsonPatchFactory create()
new NamedType(CopyOperation.class, CopyOperation.OPERATION_NAME),
new NamedType(MoveOperation.class, MoveOperation.OPERATION_NAME),
new NamedType(RemoveOperation.class, RemoveOperation.OPERATION_NAME),
new NamedType(RemoveOptionalOperation.class, RemoveOptionalOperation.OPERATION_NAME),
new NamedType(ReplaceOperation.class, ReplaceOperation.OPERATION_NAME),
new NamedType(TestOperation.class, TestOperation.OPERATION_NAME),
new NamedType(OmitOperation.class, OmitOperation.OPERATION_NAME),
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/github/fge/jsonpatch/JsonPatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,8 @@ public void serializeWithType(final JsonGenerator jgen,
{
serialize(jgen, provider);
}

public List<JsonPatchOperation> getOperations() {
return ImmutableList.copyOf(operations);
}
}
31 changes: 31 additions & 0 deletions src/main/java/com/github/fge/jsonpatch/JsonPatchModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.fge.jsonpatch;

import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.github.fge.jsonpatch.operation.AddOperation;
import com.github.fge.jsonpatch.operation.CopyOperation;
import com.github.fge.jsonpatch.operation.MoveOperation;
import com.github.fge.jsonpatch.operation.RemoveOperation;
import com.github.fge.jsonpatch.operation.ReplaceOperation;
import com.github.fge.jsonpatch.operation.TestOperation;

/**
* This module registers the standard JSON-PATCH operations with Jackson.
*/
public class JsonPatchModule extends SimpleModule {
private static final long serialVersionUID = 1L;

/**
* Constructor
*/
public JsonPatchModule() {
registerSubtypes(
new NamedType(AddOperation.class, AddOperation.OPERATION_NAME),
new NamedType(CopyOperation.class, CopyOperation.OPERATION_NAME),
new NamedType(MoveOperation.class, MoveOperation.OPERATION_NAME),
new NamedType(RemoveOperation.class, RemoveOperation.OPERATION_NAME),
new NamedType(ReplaceOperation.class, ReplaceOperation.OPERATION_NAME),
new NamedType(TestOperation.class, TestOperation.OPERATION_NAME)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,23 @@ public AddOperation(@JsonProperty("path") final JsonPointer path,
public JsonNode apply(final JsonNode node)
throws JsonPatchException
{
if (path.isEmpty())
if (getPath().isEmpty())
return value;

/*
* Check the parent node: it must exist and be a container (ie an array
* or an object) for the add operation to work.
*/
final JsonNode parentNode = path.parent().path(node);
final JsonNode parentNode = getPath().parent().path(node);
if (parentNode.isMissingNode())
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.noSuchParent"));
if (!parentNode.isContainerNode())
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.parentNotContainer"));
return parentNode.isArray()
? addToArray(path, node)
: addToObject(path, node);
? addToArray(getPath(), node)
: addToObject(getPath(), node);
}

private JsonNode addToArray(final JsonPointer path, final JsonNode node)
Expand All @@ -119,7 +119,7 @@ private JsonNode addToArray(final JsonPointer path, final JsonNode node)
final int index;
try {
index = Integer.parseInt(token.toString());
} catch (NumberFormatException ignored) {
} catch (final NumberFormatException ignored) {
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.notAnIndex"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ public JsonNode apply(final JsonNode node)
if (dupData.isMissingNode())
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.noSuchPath"));
return new AddOperation(path, dupData).apply(node);
return new AddOperation(getPath(), dupData).apply(node);
}
}
Loading