diff --git a/project.gradle b/project.gradle
index 7b66eb5..d93a5be 100644
--- a/project.gradle
+++ b/project.gradle
@@ -30,8 +30,7 @@ targetCompatibility = JavaVersion.VERSION_1_7; // defaults to sourceCompatibilit
*/
dependencies {
implementation(group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.9.9");
- implementation(group: "com.google.guava", name: "guava", version: "28.1-android");
- implementation(group: "com.github.java-json-tools", name: "msg-simple", version: "1.2-SNAPSHOT");
+ implementation(group: "com.github.fge", name: "msg-simple", version: "1.1");
implementation(group: "com.google.code.findbugs", name: "jsr305", version: "2.0.1");
testImplementation(group: "org.testng", name: "testng", version: "6.8.7") {
exclude(group: "junit", module: "junit");
@@ -51,7 +50,6 @@ javadoc {
links("https://docs.oracle.com/javase/7/docs/api/");
links("https://www.javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.1/");
links("https://fasterxml.github.io/jackson-databind/javadoc/2.2.0/");
- links("https://www.javadoc.io/doc/com.google.guava/guava/28.1-android/");
links("https://java-json-tools.github.io/msg-simple/");
}
}
diff --git a/src/main/java/com/github/fge/jackson/JacksonUtils.java b/src/main/java/com/github/fge/jackson/JacksonUtils.java
index 74c4773..85c41ff 100644
--- a/src/main/java/com/github/fge/jackson/JacksonUtils.java
+++ b/src/main/java/com/github/fge/jackson/JacksonUtils.java
@@ -29,10 +29,11 @@
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.google.common.collect.Maps;
import java.io.IOException;
import java.io.StringWriter;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -94,11 +95,11 @@ public static JsonNodeFactory nodeFactory()
*/
public static Map asMap(final JsonNode node)
{
- final Map ret = Maps.newHashMap();
if (!node.isObject())
- return ret;
+ return Collections.emptyMap();
final Iterator> iterator = node.fields();
+ final Map ret = new HashMap();
Map.Entry entry;
diff --git a/src/main/java/com/github/fge/jackson/JsonLoader.java b/src/main/java/com/github/fge/jackson/JsonLoader.java
index 0acecbf..5a3467b 100644
--- a/src/main/java/com/github/fge/jackson/JsonLoader.java
+++ b/src/main/java/com/github/fge/jackson/JsonLoader.java
@@ -20,11 +20,8 @@
package com.github.fge.jackson;
import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.base.Preconditions;
-import com.google.common.io.Closer;
import javax.annotation.Nonnull;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -74,50 +71,44 @@ private JsonLoader()
public static JsonNode fromResource(@Nonnull final String resource)
throws IOException
{
- Preconditions.checkNotNull(resource);
- Preconditions.checkArgument(resource.startsWith("/"),
- "resource path does not start with a '/'");
+ if (resource == null) {
+ throw new NullPointerException();
+ }
+ if (!resource.startsWith("/")) {
+ throw new IllegalArgumentException("resource path does not start with a '/'");
+ }
URL url;
url = JsonLoader.class.getResource(resource);
if (url == null) {
- final ClassLoader classLoader = firstNonNull(
- Thread.currentThread().getContextClassLoader(),
- JsonLoader.class.getClassLoader()
- );
+ final ClassLoader classLoader;
+ if (Thread.currentThread().getContextClassLoader() != null) {
+ classLoader = Thread.currentThread().getContextClassLoader();
+ } else if (JsonLoader.class.getClassLoader() != null) {
+ classLoader = JsonLoader.class.getClassLoader();
+ } else {
+ throw new NullPointerException();
+ }
final String s = INITIAL_SLASH.matcher(resource).replaceFirst("");
url = classLoader.getResource(s);
}
if (url == null)
throw new IOException("resource " + resource + " not found");
- final Closer closer = Closer.create();
final JsonNode ret;
- final InputStream in;
+ InputStream in = null;
try {
- in = closer.register(url.openStream());
+ in = url.openStream();
ret = READER.fromInputStream(in);
} finally {
- closer.close();
+ if (in != null) {
+ in.close();
+ }
}
return ret;
}
- /**
- * Returns the first non-null parameter.
- *
- * Implementation note: Avoids the Guava method of the same name, to mitigate 'Dependency Hell'.
- * This can be replaced by {@code MoreObjects.firstNonNull} when moving to Guava >= 18.0
- * (Tip: Guava 20 seems like a good choice if Java 6 support is still necessary.)
- *
- * @throws NullPointerException if both are null.
- */
- private static ClassLoader firstNonNull(ClassLoader first, ClassLoader second)
- {
- return first != null ? first : Preconditions.checkNotNull(second);
- }
-
/**
* Read a {@link JsonNode} from an URL.
*
@@ -141,15 +132,16 @@ public static JsonNode fromURL(final URL url)
public static JsonNode fromPath(final String path)
throws IOException
{
- final Closer closer = Closer.create();
final JsonNode ret;
- final FileInputStream in;
+ FileInputStream in = null;
try {
- in = closer.register(new FileInputStream(path));
+ in = new FileInputStream(path);
ret = READER.fromInputStream(in);
} finally {
- closer.close();
+ if (in != null) {
+ in.close();
+ }
}
return ret;
@@ -166,15 +158,16 @@ public static JsonNode fromPath(final String path)
public static JsonNode fromFile(final File file)
throws IOException
{
- final Closer closer = Closer.create();
final JsonNode ret;
- final FileInputStream in;
+ FileInputStream in = null;
try {
- in = closer.register(new FileInputStream(file));
+ in = new FileInputStream(file);
ret = READER.fromInputStream(in);
} finally {
- closer.close();
+ if (in != null) {
+ in.close();
+ }
}
return ret;
diff --git a/src/main/java/com/github/fge/jackson/JsonNodeReader.java b/src/main/java/com/github/fge/jackson/JsonNodeReader.java
index 61e5e50..2e6c622 100644
--- a/src/main/java/com/github/fge/jackson/JsonNodeReader.java
+++ b/src/main/java/com/github/fge/jackson/JsonNodeReader.java
@@ -30,7 +30,6 @@
import com.github.fge.Builder;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.bundle.PropertiesBundle;
-import com.google.common.io.Closer;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
@@ -93,16 +92,20 @@ public JsonNodeReader()
public JsonNode fromInputStream(final InputStream in)
throws IOException
{
- final Closer closer = Closer.create();
- final JsonParser parser;
- final MappingIterator iterator;
+ JsonParser parser = null;
+ MappingIterator iterator = null;
try {
- parser = closer.register(reader.getFactory().createParser(in));
+ parser = reader.getFactory().createParser(in);
iterator = reader.readValues(parser);
- return readNode(closer.register(iterator));
+ return readNode(iterator);
} finally {
- closer.close();
+ if (parser != null) {
+ parser.close();
+ }
+ if (iterator != null) {
+ iterator.close();
+ }
}
}
@@ -117,16 +120,20 @@ public JsonNode fromInputStream(final InputStream in)
public JsonNode fromReader(final Reader r)
throws IOException
{
- final Closer closer = Closer.create();
- final JsonParser parser;
- final MappingIterator iterator;
+ JsonParser parser = null;
+ MappingIterator iterator = null;
try {
- parser = closer.register(reader.getFactory().createParser(r));
+ parser = reader.getFactory().createParser(r);
iterator = reader.readValues(parser);
- return readNode(closer.register(iterator));
+ return readNode(iterator);
} finally {
- closer.close();
+ if (parser != null) {
+ parser.close();
+ }
+ if (iterator != null) {
+ iterator.close();
+ }
}
}
diff --git a/src/main/java/com/github/fge/jackson/JsonNumEquals.java b/src/main/java/com/github/fge/jackson/JsonNumEquals.java
index 011fe3d..f098d4b 100644
--- a/src/main/java/com/github/fge/jackson/JsonNumEquals.java
+++ b/src/main/java/com/github/fge/jackson/JsonNumEquals.java
@@ -20,15 +20,15 @@
package com.github.fge.jackson;
import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.base.Equivalence;
-import com.google.common.collect.Sets;
+import javax.annotation.Nullable;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
- * An {@link Equivalence} strategy for JSON Schema equality
+ * An {@code com.google.common.base.Equivalence} like strategy for JSON Schema equality
*
*
{@link JsonNode} does a pretty good job of obeying the {@link
* Object#equals(Object) equals()}/{@link Object#hashCode() hashCode()}
@@ -41,21 +41,50 @@
* kind of equality.
*/
public final class JsonNumEquals
- extends Equivalence
{
- private static final Equivalence INSTANCE
+ private static final JsonNumEquals INSTANCE
= new JsonNumEquals();
private JsonNumEquals()
{
}
- public static Equivalence getInstance()
+ public static JsonNumEquals getInstance()
{
return INSTANCE;
}
- @Override
+ /**
+ * Returns {@code true} if the given objects are considered equivalent.
+ *
+ *
The {@code equivalent} method implements an equivalence relation on object references:
+ *
+ *
+ *
It is reflexive: for any reference {@code x}, including null, {@code
+ * equivalent(x, x)} returns {@code true}.
+ *
It is symmetric: for any references {@code x} and {@code y}, {@code
+ * equivalent(x, y) == equivalent(y, x)}.
+ *
It is transitive: for any references {@code x}, {@code y}, and {@code z}, if
+ * {@code equivalent(x, y)} returns {@code true} and {@code equivalent(y, z)} returns {@code
+ * true}, then {@code equivalent(x, z)} returns {@code true}.
+ *
It is consistent: for any references {@code x} and {@code y}, multiple invocations
+ * of {@code equivalent(x, y)} consistently return {@code true} or consistently return {@code
+ * false} (provided that neither {@code x} nor {@code y} is modified).
+ *
+ * @param a x
+ * @param b y
+ * @return whether nodes are equal according to IETF RFCs
+ */
+ public final boolean equivalent(@Nullable JsonNode a, @Nullable JsonNode b) {
+ if (a == b) {
+ return true;
+ }
+ if (a == null || b == null) {
+ return false;
+ }
+ return doEquivalent(a, b);
+ }
+
protected boolean doEquivalent(final JsonNode a, final JsonNode b)
{
/*
@@ -93,7 +122,31 @@ protected boolean doEquivalent(final JsonNode a, final JsonNode b)
return typeA == NodeType.ARRAY ? arrayEquals(a, b) : objectEquals(a, b);
}
- @Override
+ /**
+ * Returns a hash code for {@code t}.
+ *
+ *
The {@code hash} has the following properties:
+ *
+ *
It is consistent: for any reference {@code x}, multiple invocations of
+ * {@code hash(x}} consistently return the same value provided {@code x} remains unchanged
+ * according to the definition of the equivalence. The hash need not remain consistent from
+ * one execution of an application to another execution of the same application.
+ *
It is distributable across equivalence: for any references {@code x} and {@code y},
+ * if {@code equivalent(x, y)}, then {@code hash(x) == hash(y)}. It is not necessary
+ * that the hash be distributable across inequivalence. If {@code equivalence(x, y)}
+ * is false, {@code hash(x) == hash(y)} may still be true.
+ *
{@code hash(null)} is {@code 0}.
+ *
+ * @param t node to hash
+ * @return hash
+ */
+ public final int hash(@Nullable JsonNode t) {
+ if (t == null) {
+ return 0;
+ }
+ return doHash(t);
+ }
+
protected int doHash(final JsonNode t)
{
/*
@@ -183,13 +236,32 @@ private boolean objectEquals(final JsonNode a, final JsonNode b)
/*
* Grab the key set from the first node
*/
- final Set keys = Sets.newHashSet(a.fieldNames());
-
+ final Set keys = new HashSet();
+ Iterator iterator1 = a.fieldNames();
+ while (iterator1.hasNext()) {
+ final String next = iterator1.next();
+ if (next != null) {
+ keys.add(next);
+ } else {
+ throw new NullPointerException();
+ }
+ }
+// final Set keys = Sets.newHashSet(a.fieldNames());
/*
* Grab the key set from the second node, and see if both sets are the
* same. If not, objects are not equal, no need to check for children.
*/
- final Set set = Sets.newHashSet(b.fieldNames());
+ final Set set = new HashSet();
+ Iterator iterator2 = b.fieldNames();
+ while (iterator2.hasNext()) {
+ final String next = iterator2.next();
+ if (next != null) {
+ set.add(next);
+ } else {
+ throw new NullPointerException();
+ }
+ }
+
if (!set.equals(keys))
return false;
diff --git a/src/main/java/com/github/fge/jackson/NodeType.java b/src/main/java/com/github/fge/jackson/NodeType.java
index 7fb14cd..ea15551 100644
--- a/src/main/java/com/github/fge/jackson/NodeType.java
+++ b/src/main/java/com/github/fge/jackson/NodeType.java
@@ -22,10 +22,10 @@
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.MissingNode;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
import java.util.EnumMap;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -98,13 +98,13 @@ public enum NodeType
TOKEN_MAP.put(JsonToken.START_OBJECT, OBJECT);
TOKEN_MAP.put(JsonToken.VALUE_STRING, STRING);
- final ImmutableMap.Builder builder
- = ImmutableMap.builder();
+ final Map builder
+ = new HashMap();
for (final NodeType type: NodeType.values())
builder.put(type.name, type);
- NAME_MAP = builder.build();
+ NAME_MAP = Collections.unmodifiableMap(builder);
}
NodeType(final String name)
@@ -140,8 +140,9 @@ public static NodeType getNodeType(final JsonNode node)
{
final JsonToken token = node.asToken();
final NodeType ret = TOKEN_MAP.get(token);
-
- Preconditions.checkNotNull(ret, "unhandled token type " + token);
+ if (ret == null) {
+ throw new NullPointerException("unhandled token type " + token);
+ }
return ret;
}
diff --git a/src/main/java/com/github/fge/jackson/jsonpointer/JsonPointer.java b/src/main/java/com/github/fge/jackson/jsonpointer/JsonPointer.java
index 9f3a0ca..670e50b 100644
--- a/src/main/java/com/github/fge/jackson/jsonpointer/JsonPointer.java
+++ b/src/main/java/com/github/fge/jackson/jsonpointer/JsonPointer.java
@@ -22,10 +22,10 @@
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.MissingNode;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
import javax.annotation.concurrent.Immutable;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
@@ -44,7 +44,7 @@ public final class JsonPointer
* The empty JSON Pointer
*/
private static final JsonPointer EMPTY
- = new JsonPointer(ImmutableList.>of());
+ = new JsonPointer(Collections.>emptyList());
/**
* Return an empty JSON Pointer
@@ -72,7 +72,7 @@ public static JsonPointer empty()
*/
public static JsonPointer of(final Object first, final Object... other)
{
- final List tokens = Lists.newArrayList();
+ final List tokens = new ArrayList();
tokens.add(ReferenceToken.fromRaw(first.toString()));
@@ -120,7 +120,14 @@ public JsonPointer append(final String raw)
final ReferenceToken refToken = ReferenceToken.fromRaw(raw);
final JsonNodeResolver resolver = new JsonNodeResolver(refToken);
final List> list
- = Lists.newArrayList(tokenResolvers);
+ = new ArrayList>();
+ for (final TokenResolver tokenResolver : tokenResolvers) {
+ if (tokenResolver != null) {
+ list.add(tokenResolver);
+ } else {
+ throw new NullPointerException();
+ }
+ }
list.add(resolver);
return new JsonPointer(list);
}
@@ -147,7 +154,14 @@ public JsonPointer append(final JsonPointer other)
{
BUNDLE.checkNotNull(other, "nullInput");
final List> list
- = Lists.newArrayList(tokenResolvers);
+ = new ArrayList>();
+ for (final TokenResolver tokenResolver : tokenResolvers) {
+ if (tokenResolver != null) {
+ list.add(tokenResolver);
+ } else {
+ throw new NullPointerException();
+ }
+ }
list.addAll(other.tokenResolvers);
return new JsonPointer(list);
}
@@ -177,7 +191,7 @@ public JsonPointer parent()
private static List> fromTokens(
final List tokens)
{
- final List> list = Lists.newArrayList();
+ final List> list = new ArrayList>();
for (final ReferenceToken token: tokens)
list.add(new JsonNodeResolver(token));
return list;
diff --git a/src/main/java/com/github/fge/jackson/jsonpointer/ReferenceToken.java b/src/main/java/com/github/fge/jackson/jsonpointer/ReferenceToken.java
index 47d9891..8fd7c1a 100644
--- a/src/main/java/com/github/fge/jackson/jsonpointer/ReferenceToken.java
+++ b/src/main/java/com/github/fge/jackson/jsonpointer/ReferenceToken.java
@@ -21,10 +21,12 @@
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.load.MessageBundles;
-import com.google.common.collect.ImmutableList;
-import java.nio.CharBuffer;
import javax.annotation.concurrent.Immutable;
+import java.nio.CharBuffer;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
/**
@@ -54,14 +56,14 @@ public final class ReferenceToken
/**
* List of encoding characters in a cooked token
*/
- private static final ImmutableList ENCODED = ImmutableList.of('0', '1');
+ private static final List ENCODED = Collections.unmodifiableList(Arrays.asList('0', '1'));
/**
* List of sequences to encode in a raw token
*
*
This list and {@link #ENCODED} have matching indices on purpose.
*/
- private static final ImmutableList DECODED = ImmutableList.of('~', '/');
+ private static final List DECODED = Collections.unmodifiableList(Arrays.asList('~', '/'));
/**
* The cooked representation of that token
diff --git a/src/main/java/com/github/fge/jackson/jsonpointer/TreePointer.java b/src/main/java/com/github/fge/jackson/jsonpointer/TreePointer.java
index a493b9c..df82ef8 100644
--- a/src/main/java/com/github/fge/jackson/jsonpointer/TreePointer.java
+++ b/src/main/java/com/github/fge/jackson/jsonpointer/TreePointer.java
@@ -26,12 +26,12 @@
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.load.MessageBundles;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
+import javax.annotation.concurrent.ThreadSafe;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import javax.annotation.concurrent.ThreadSafe;
/**
* A pointer into a {@link TreeNode}
@@ -92,7 +92,7 @@ protected TreePointer(final T missing,
final List> tokenResolvers)
{
this.missing = missing;
- this.tokenResolvers = ImmutableList.copyOf(tokenResolvers);
+ this.tokenResolvers = Collections.unmodifiableList(new ArrayList>(tokenResolvers));
}
/**
@@ -174,7 +174,7 @@ public final boolean equals(final Object obj)
return false;
if (this == obj)
return true;
- if (!(obj instanceof TreePointer))
+ if (getClass() != obj.getClass())
return false;
final TreePointer> other = (TreePointer>) obj;
return tokenResolvers.equals(other.tokenResolvers);
@@ -206,7 +206,7 @@ protected static List tokensFromInput(final String input)
throws JsonPointerException
{
String s = BUNDLE.checkNotNull(input, "nullInput");
- final List ret = Lists.newArrayList();
+ final List ret = new ArrayList();
String cooked;
int index;
char c;
diff --git a/src/main/java/com/github/fge/jackson/package-info.java b/src/main/java/com/github/fge/jackson/package-info.java
index 8cb501c..44641ad 100644
--- a/src/main/java/com/github/fge/jackson/package-info.java
+++ b/src/main/java/com/github/fge/jackson/package-info.java
@@ -34,7 +34,7 @@
* com.fasterxml.jackson.databind.DeserializationFeature#USE_BIG_DECIMAL_FOR_FLOATS}.
*
*
- *
{@link com.github.fge.jackson.JsonNumEquals} is an {@link
+ *
{@link com.github.fge.jackson.JsonNumEquals} is an {@code
* com.google.common.base.Equivalence} over {@link
* com.fasterxml.jackson.databind.JsonNode} for recursive equivalence of JSON
* number values.
an {@link com.google.common.base.Equivalence} over {@link
+
an {@code com.google.common.base.Equivalence} over {@link
com.fasterxml.jackson.databind.JsonNode} for numeric JSON values;
a generalized JSON
pointer implementation over Jackson's {@link
@@ -63,7 +63,7 @@
JSON numeric equivalence
and 1.0 yield different
types of nodes.
-
This package provides an {@link com.google.common.base.Equivalence} to
+
This package provides an {@code com.google.common.base.Equivalence} to
ensure that two numeric nodes are considered equivalent if their mathematical
value is the same. See the javadoc for more information on how to use it.