Upgrade fasterXML libraries for OS-9
Upgrade fasterXML to version 2.9.5 to address security vulnerability
Wrap calls to treeRead(InputStream) to handle new behavior of null streams
Change-Id: Id199cfacd0cf9e5371dc33de9f1e058c2e72eaa5
diff --git a/utils/misc/BUCK b/utils/misc/BUCK
index 5b06b9c..aef407f 100644
--- a/utils/misc/BUCK
+++ b/utils/misc/BUCK
@@ -4,6 +4,7 @@
'//lib:METRICS',
'//lib:KRYO',
'//lib:netty',
+ '//lib:JACKSON',
]
osgi_jar_with_tests(
diff --git a/utils/misc/src/main/java/org/onlab/util/Tools.java b/utils/misc/src/main/java/org/onlab/util/Tools.java
index 057441e..ebcf472 100644
--- a/utils/misc/src/main/java/org/onlab/util/Tools.java
+++ b/utils/misc/src/main/java/org/onlab/util/Tools.java
@@ -15,6 +15,8 @@
*/
package org.onlab.util;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Charsets;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
@@ -24,6 +26,7 @@
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
@@ -73,6 +76,8 @@
private static Random random = new Random();
+ private static final String INPUT_JSON_CANNOT_BE_NULL = "Input JSON cannot be null";
+
/**
* Returns a thread factory that produces threads named according to the
* supplied name pattern.
@@ -216,6 +221,19 @@
}
/**
+ * Utility to convert a mapper and an input stream into a JSON tree,
+ * and be tolerant of a null tree being returned.
+ *
+ * @param mapper JSON object mapper
+ * @param stream IO stream containing the JSON
+ * @return object node for the given
+ * @throws IOException if JSON parsing fails
+ */
+ public static ObjectNode readTreeFromStream(ObjectMapper mapper, InputStream stream) throws IOException {
+ return nullIsIllegal((ObjectNode) mapper.readTree(stream), INPUT_JSON_CANNOT_BE_NULL);
+ }
+
+ /**
* Converts a string from hex to long.
*
* @param string hex number in string form; sans 0x