Skip to content

Introduce OmitOperation #1

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

Closed
wants to merge 8 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ META-INF
out
build
.gradle
gradle.properties

52 changes: 15 additions & 37 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,24 @@
* - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt
*/

buildscript {
repositories {
maven {
url "http://repo.springsource.org/plugins-release";
}
}
dependencies {
classpath(group: "org.springframework.build.gradle",
name: "propdeps-plugin", version: "0.0.7");
}
};

configure(allprojects) {
apply(plugin: "propdeps");
apply(plugin: "propdeps-maven");
apply(plugin: "propdeps-idea");
apply(plugin: "propdeps-eclipse");
}

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

group = "com.github.fge";
version = "1.10-SNAPSHOT";
description = "JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7386) implementation in Java";
group = "com.box";
version = "1.11";
sourceCompatibility = "1.6";
targetCompatibility = "1.6"; // defaults to sourceCompatibility

/*
* List of dependencies
*/
dependencies {
provided(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");
Expand Down Expand Up @@ -121,7 +99,7 @@ artifacts {
}

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

Expand All @@ -134,9 +112,9 @@ task pom << {
*/

project.ext {
gitrwscm = sprintf("[email protected]:fge/%s", name);
gitroscm = sprintf("https://github.com/fge/%s.git", name);
projectURL = sprintf("https://github.com/fge/%s", name);
description = "JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7386) implementation in Java";
scmURL = sprintf("git@github.com: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/";
};
Expand Down Expand Up @@ -190,13 +168,13 @@ uploadArchives {
pom.project {
name "${project.name}";
packaging "jar";
description "${project.description}";
description "${project.ext.description}";
url "${projectURL}";

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

licenses {
Expand All @@ -214,9 +192,9 @@ uploadArchives {

developers {
developer {
id "fge";
name "Francis Galiegue";
email "fgaliegue@gmail.com";
id "metadata-dev";
name "Metadata Dev";
email "metadata-dev@box.com";
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions dorelease.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,19 @@
# This will build everything that is needed and push to Maven central.
#

# Release instructions
# 1. Follow the gpg setup instructions: http://central.sonatype.org/pages/working-with-pgp-signatures.html
# 2. In project root create gradle.properties and add:
# sonatypeUsername=metadata-dev
# sonatypePassword=password in vault for oss sonatype<ensure newline>
#
# signing.keyId=generated key
# signing.password=password for gpg key
# signing.secretKeyRingFile=/Users/username/.gnupg/secring.gpg
# 3. ./dorelease.sh
# 4. Go to UI at: https://oss.sonatype.org
# 5. Login as metadata-dev
# 6. Follow the instructions here: http://central.sonatype.org/pages/releasing-the-deployment.html

./gradlew --recompile-scripts clean test uploadArchives

23 changes: 2 additions & 21 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
#
# Copyright (c) 2014, Francis Galiegue ([email protected])
#
# This software is dual-licensed under:
#
# - the Lesser General Public License (LGPL) version 3.0 or, at your option, any
# later version;
# - the Apache Software License (ASL) version 2.0.
#
# The text of this file and of both licenses is available at the root of this
# project or, if you have the jar distribution, in directory META-INF/, under
# the names LGPL-3.0.txt and ASL-2.0.txt respectively.
#
# Direct link to the sources:
#
# - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt
# - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt
#

#Mon Apr 14 13:20:00 CEST 2014
#Sat Sep 05 14:30:45 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-2.5-all.zip
5 changes: 4 additions & 1 deletion src/main/java/com/github/fge/jsonpatch/AddOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@
public final class AddOperation
extends PathValueOperation
{
public static final String OPERATION_NAME = "add";

private static final ReferenceToken LAST_ARRAY_ELEMENT
= ReferenceToken.fromRaw("-");

@JsonCreator
public AddOperation(@JsonProperty("path") final JsonPointer path,
@JsonProperty("value") final JsonNode value)
{
super("add", path, value);
super(OPERATION_NAME, path, value);
}

@Override
Expand Down Expand Up @@ -137,3 +139,4 @@ private JsonNode addToObject(final JsonPointer path, final JsonNode node)
return ret;
}
}

13 changes: 13 additions & 0 deletions src/main/java/com/github/fge/jsonpatch/AddOperationFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.fge.jsonpatch;

public final class AddOperationFactory extends JsonPatchOperationFactoryBase
{
public String getOperationName()
{
return AddOperation.OPERATION_NAME;
}
public Class<? extends JsonPatchOperation> getOperationClass()
{
return AddOperation.class;
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/github/fge/jsonpatch/CopyOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
public final class CopyOperation
extends DualPathOperation
{
public static final String OPERATION_NAME = "copy";

@JsonCreator
public CopyOperation(@JsonProperty("from") final JsonPointer from,
@JsonProperty("path") final JsonPointer path)
Expand All @@ -61,3 +63,4 @@ public JsonNode apply(final JsonNode node)
return new AddOperation(path, dupData).apply(node);
}
}

13 changes: 13 additions & 0 deletions src/main/java/com/github/fge/jsonpatch/CopyOperationFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.fge.jsonpatch;

public final class CopyOperationFactory extends JsonPatchOperationFactoryBase
{
public String getOperationName()
{
return CopyOperation.OPERATION_NAME;
}
public Class<? extends JsonPatchOperation> getOperationClass()
{
return CopyOperation.class;
}
}
14 changes: 12 additions & 2 deletions src/main/java/com/github/fge/jsonpatch/DualPathOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,27 @@
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.github.fge.jackson.jsonpointer.JsonPointer;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.load.MessageBundles;

import java.io.IOException;

/**
* Base class for JSON Patch operations taking two JSON Pointers as arguments
*/
public abstract class DualPathOperation
extends JsonPatchOperation
implements JsonPatchOperation
{
protected static final MessageBundle BUNDLE
= MessageBundles.getBundle(JsonPatchMessages.class);

protected final String op;

@JsonSerialize(using = ToStringSerializer.class)
protected final JsonPointer from;

protected final JsonPointer path;

/**
* Protected constructor
*
Expand All @@ -48,8 +57,9 @@ public abstract class DualPathOperation
protected DualPathOperation(final String op, final JsonPointer from,
final JsonPointer path)
{
super(op, path);
this.op = op;
this.from = from;
this.path = path;
}

@Override
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/github/fge/jsonpatch/JsonPatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,14 @@ public JsonPatch(final List<JsonPatchOperation> operations)
*
* @param node the JSON representation of the generated JSON Patch
* @return a JSON Patch
* @throws IOException input is not a valid JSON patch
* @throws JsonPatchException input is not a valid JSON patch
* @throws NullPointerException input is null
*/
public static JsonPatch fromJson(final JsonNode node)
throws IOException
throws JsonPatchException
{
BUNDLE.checkNotNull(node, "jsonPatch.nullInput");
return JacksonUtils.getReader().withType(JsonPatch.class)
.readValue(node);
return JsonPatchFactoryUtil.defaultFactory().fromJson(node);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/github/fge/jsonpatch/JsonPatchFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.fge.jsonpatch;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;

import java.io.IOException;

/**
* A JsonPatchFactory is able to create a JsonPatch from a JsonNode.
*/
public interface JsonPatchFactory
{
/**
* Creates a JsonPatch from a JsonNode
* @param node The node to process
* @return The JsonPatch that can be applied to a JsonNode
* @throws JsonPatchException
*/
public JsonPatch fromJson(JsonNode node) throws JsonPatchException;
}
57 changes: 57 additions & 0 deletions src/main/java/com/github/fge/jsonpatch/JsonPatchFactoryUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.github.fge.jsonpatch;

import java.util.*;

/**
* Utilities for JsonPatchFactory. It provides a default implementation of JsonPatchFactory that
* has all the RFC6902 operations registered.
*/
public final class JsonPatchFactoryUtil
{
private static final List<JsonPatchOperationFactory> DEFAULT_OPERATIONS =
Collections.unmodifiableList(
new ArrayList<JsonPatchOperationFactory>() {{
add(new AddOperationFactory());
add(new CopyOperationFactory());
add(new MoveOperationFactory());
add(new RemoveOperationFactory());
add(new ReplaceOperationFactory());
add(new TestOperationFactory());
}}
);
private static final List<JsonPatchOperationFactory> EXTENDED_OPERATIONS =
Collections.unmodifiableList(
new ArrayList<JsonPatchOperationFactory>() {{
add(new OmitOperationFactory());
}}
);
private static final JsonPatchFactory DEFAULT_FACTORY =
(new RegistryBasedJsonPatchFactory.Builder())
.addOperations(DEFAULT_OPERATIONS)
.build();

private static final JsonPatchFactory EXTENDED_FACTORY =
(new RegistryBasedJsonPatchFactory.Builder())
.addOperations(DEFAULT_OPERATIONS)
.addOperations(EXTENDED_OPERATIONS)
.build();

public static List<JsonPatchOperationFactory> defaultOperations()
{
return DEFAULT_OPERATIONS;
}
public static JsonPatchFactory defaultFactory()
{
return DEFAULT_FACTORY;
}
public static List<JsonPatchOperationFactory> extendedOperations()
{
return EXTENDED_OPERATIONS;
}
public static JsonPatchFactory extendedFactory()
{
return EXTENDED_FACTORY;
}

private JsonPatchFactoryUtil() {}
}
Loading