taskLoggerThreadLocal = new ThreadLocal<>();
+ private FileUtils() {
+ throw new UnsupportedOperationException("Construct FileUtils");
+ }
+
/**
* get file suffix
*
@@ -80,7 +86,7 @@ public class FileUtils {
String fileName = String.format("%s/download/%s/%s", DATA_BASEDIR, DateUtils.getCurrentTime(YYYYMMDDHHMMSS), filename);
File file = new File(fileName);
- if (!file.getParentFile().exists()){
+ if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
@@ -97,7 +103,7 @@ public class FileUtils {
public static String getUploadFilename(String tenantCode, String filename) {
String fileName = String.format("%s/%s/resources/%s", DATA_BASEDIR, tenantCode, filename);
File file = new File(fileName);
- if (!file.getParentFile().exists()){
+ if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
@@ -106,6 +112,7 @@ public class FileUtils {
/**
* directory of process execution
+ *
* @param projectId project id
* @param processDefineId process definition id
* @param processInstanceId process instance id
@@ -114,9 +121,9 @@ public class FileUtils {
*/
public static String getProcessExecDir(int projectId, int processDefineId, int processInstanceId, int taskInstanceId) {
String fileName = String.format("%s/exec/process/%s/%s/%s/%s", DATA_BASEDIR, Integer.toString(projectId),
- Integer.toString(processDefineId), Integer.toString(processInstanceId),Integer.toString(taskInstanceId));
+ Integer.toString(processDefineId), Integer.toString(processInstanceId), Integer.toString(taskInstanceId));
File file = new File(fileName);
- if (!file.getParentFile().exists()){
+ if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
@@ -125,6 +132,7 @@ public class FileUtils {
/**
* directory of process instances
+ *
* @param projectId project id
* @param processDefineId process definition id
* @param processInstanceId process instance id
@@ -150,6 +158,7 @@ public class FileUtils {
/**
* create directory and user
+ *
* @param execLocalPath execute local path
* @param userName user name
* @throws IOException errors
@@ -190,12 +199,11 @@ public class FileUtils {
OSUtils.taskLoggerThreadLocal.remove();
}
-
/**
* write content to file ,if parent path not exists, it will do one's utmost to mkdir
*
- * @param content content
- * @param filePath target file path
+ * @param content content
+ * @param filePath target file path
* @return true if write success
*/
public static boolean writeContent2File(String content, String filePath) {
@@ -231,13 +239,13 @@ public class FileUtils {
/**
* Writes a String to a file creating the file if it does not exist.
- *
+ *
* NOTE: As from v1.3, the parent directories of the file will be created
* if they do not exist.
*
- * @param file the file to write
- * @param data the content to write to the file
- * @param encoding the encoding to use, {@code null} means platform default
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param encoding the encoding to use, {@code null} means platform default
* @throws IOException in case of an I/O error
* @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
* @since 2.4
@@ -248,13 +256,13 @@ public class FileUtils {
/**
* Writes a String to a file creating the file if it does not exist.
- *
+ *
* NOTE: As from v1.3, the parent directories of the file will be created
* if they do not exist.
*
- * @param file the file to write
- * @param data the content to write to the file
- * @param encoding the encoding to use, {@code null} means platform default
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param encoding the encoding to use, {@code null} means platform default
* @throws IOException in case of an I/O error
* @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
*/
@@ -265,9 +273,9 @@ public class FileUtils {
/**
* Writes a String to a file creating the file if it does not exist.
*
- * @param file the file to write
- * @param data the content to write to the file
- * @param encoding the encoding to use, {@code null} means platform default
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param encoding the encoding to use, {@code null} means platform default
* @param append if {@code true}, then the String will be added to the
* end of the file rather than overwriting
* @throws IOException in case of an I/O error
@@ -287,15 +295,14 @@ public class FileUtils {
/**
* Writes a String to a file creating the file if it does not exist.
*
- * @param file the file to write
- * @param data the content to write to the file
- * @param encoding the encoding to use, {@code null} means platform default
+ * @param file the file to write
+ * @param data the content to write to the file
+ * @param encoding the encoding to use, {@code null} means platform default
* @param append if {@code true}, then the String will be added to the
* end of the file rather than overwriting
* @throws IOException in case of an I/O error
- * @throws UnsupportedCharsetException
- * thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
- * supported by the VM
+ * @throws UnsupportedCharsetException thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
+ * supported by the VM
* @since 2.1
*/
public static void writeStringToFile(File file, String data, String encoding, boolean append) throws IOException {
@@ -305,8 +312,8 @@ public class FileUtils {
/**
* Writes a String to a file creating the file if it does not exist using the default encoding for the VM.
*
- * @param file the file to write
- * @param data the content to write to the file
+ * @param file the file to write
+ * @param data the content to write to the file
* @throws IOException in case of an I/O error
*/
public static void writeStringToFile(File file, String data) throws IOException {
@@ -316,8 +323,8 @@ public class FileUtils {
/**
* Writes a String to a file creating the file if it does not exist using the default encoding for the VM.
*
- * @param file the file to write
- * @param data the content to write to the file
+ * @param file the file to write
+ * @param data the content to write to the file
* @param append if {@code true}, then the String will be added to the
* end of the file rather than overwriting
* @throws IOException in case of an I/O error
@@ -340,7 +347,7 @@ public class FileUtils {
* An exception is thrown if the file exists but cannot be written to.
* An exception is thrown if the parent directory cannot be created.
*
- * @param file the file to open for output, must not be {@code null}
+ * @param file the file to open for output, must not be {@code null}
* @return a new {@link FileOutputStream} for the specified file
* @throws IOException if the file object is a directory
* @throws IOException if the file cannot be written to
@@ -364,7 +371,7 @@ public class FileUtils {
* An exception is thrown if the file exists but cannot be written to.
* An exception is thrown if the parent directory cannot be created.
*
- * @param file the file to open for output, must not be {@code null}
+ * @param file the file to open for output, must not be {@code null}
* @param append if {@code true}, then bytes will be added to the
* end of the file rather than overwriting
* @return a new {@link FileOutputStream} for the specified file
@@ -384,15 +391,15 @@ public class FileUtils {
} else {
File parent = file.getParentFile();
if (parent != null && !parent.mkdirs() && !parent.isDirectory()) {
- throw new IOException("Directory '" + parent + "' could not be created");
+ throw new IOException("Directory '" + parent + "' could not be created");
}
}
return new FileOutputStream(file, append);
}
-
/**
* deletes a directory recursively
+ *
* @param dir directory
* @throws IOException in case deletion is unsuccessful
*/
@@ -420,17 +427,18 @@ public class FileUtils {
/**
* Gets all the parent subdirectories of the parentDir directory
+ *
* @param parentDir parent dir
* @return all dirs
*/
- public static File[] getAllDir(String parentDir){
- if(parentDir == null || "".equals(parentDir)) {
+ public static File[] getAllDir(String parentDir) {
+ if (parentDir == null || "".equals(parentDir)) {
throw new RuntimeException("parentDir can not be empty");
}
File file = new File(parentDir);
- if(!file.exists() || !file.isDirectory()) {
- throw new RuntimeException("parentDir not exist, or is not a directory:"+parentDir);
+ if (!file.exists() || !file.isDirectory()) {
+ throw new RuntimeException("parentDir not exist, or is not a directory:" + parentDir);
}
return file.listFiles(File::isDirectory);
@@ -438,6 +446,7 @@ public class FileUtils {
/**
* Get Content
+ *
* @param inputStream input stream
* @return string of input stream
*/
@@ -447,15 +456,14 @@ public class FileUtils {
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
- while ((length= inputStream.read(buffer)) != -1) {
- output.write(buffer,0,length);
+ while ((length = inputStream.read(buffer)) != -1) {
+ output.write(buffer, 0, length);
}
return output.toString();
} catch (Exception e) {
- logger.error(e.getMessage(),e);
+ logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
-
}
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HttpUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HttpUtils.java
index 7d1e0a523af99630bbf2c1dde2eea8d187e9e1ac..36b437f3122b8af809ce7973dba8fe9343a20918 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HttpUtils.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HttpUtils.java
@@ -14,9 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.dolphinscheduler.common.utils;
import org.apache.dolphinscheduler.common.Constants;
+
import org.apache.http.HttpEntity;
import org.apache.http.client.config.AuthSchemes;
import org.apache.http.client.config.CookieSpecs;
@@ -30,148 +32,148 @@ import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* http utils
*/
public class HttpUtils {
+ public static final Logger logger = LoggerFactory.getLogger(HttpUtils.class);
- public static final Logger logger = LoggerFactory.getLogger(HttpUtils.class);
-
- private HttpUtils() {
-
- }
-
- public static CloseableHttpClient getInstance(){
- return HttpClientInstance.httpClient;
- }
-
- private static class HttpClientInstance{
- private static final CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(requestConfig).build();
- }
-
-
- private static PoolingHttpClientConnectionManager cm;
-
- private static SSLContext ctx = null;
-
- private static SSLConnectionSocketFactory socketFactory;
-
- private static RequestConfig requestConfig;
-
- private static Registry socketFactoryRegistry;
-
- private static X509TrustManager xtm = new X509TrustManager() {
- @Override
- public void checkClientTrusted(X509Certificate[] chain, String authType) {
- }
-
- @Override
- public void checkServerTrusted(X509Certificate[] chain, String authType) {
- }
+ private HttpUtils() {
+ throw new UnsupportedOperationException("Construct HttpUtils");
+ }
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- return null;
- }
- };
+ public static CloseableHttpClient getInstance() {
+ return HttpClientInstance.httpClient;
+ }
- static {
- try {
- ctx = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
- ctx.init(null, new TrustManager[] { xtm }, null);
- } catch (NoSuchAlgorithmException e) {
- logger.error("SSLContext init with NoSuchAlgorithmException", e);
- } catch (KeyManagementException e) {
- logger.error("SSLContext init with KeyManagementException", e);
- }
- socketFactory = new SSLConnectionSocketFactory(ctx, NoopHostnameVerifier.INSTANCE);
- /** set timeout、request time、socket timeout */
- requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES)
- .setExpectContinueEnabled(Boolean.TRUE)
- .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
- .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
- .setConnectTimeout(Constants.HTTP_CONNECT_TIMEOUT).setSocketTimeout(Constants.SOCKET_TIMEOUT)
- .setConnectionRequestTimeout(Constants.HTTP_CONNECTION_REQUEST_TIMEOUT).setRedirectsEnabled(true)
- .build();
- socketFactoryRegistry = RegistryBuilder.create()
- .register("http", PlainConnectionSocketFactory.INSTANCE).register("https", socketFactory).build();
- cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
- cm.setDefaultMaxPerRoute(60);
- cm.setMaxTotal(100);
+ private static class HttpClientInstance {
+ private static final CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(requestConfig).build();
+ }
- }
+ private static PoolingHttpClientConnectionManager cm;
+
+ private static SSLContext ctx = null;
+
+ private static SSLConnectionSocketFactory socketFactory;
+
+ private static RequestConfig requestConfig;
+
+ private static Registry socketFactoryRegistry;
+
+ private static X509TrustManager xtm = new X509TrustManager() {
+ @Override
+ public void checkClientTrusted(X509Certificate[] chain, String authType) {
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] chain, String authType) {
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+ };
+
+ static {
+ try {
+ ctx = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
+ ctx.init(null, new TrustManager[]{xtm}, null);
+ } catch (NoSuchAlgorithmException e) {
+ logger.error("SSLContext init with NoSuchAlgorithmException", e);
+ } catch (KeyManagementException e) {
+ logger.error("SSLContext init with KeyManagementException", e);
+ }
+ socketFactory = new SSLConnectionSocketFactory(ctx, NoopHostnameVerifier.INSTANCE);
+ /** set timeout、request time、socket timeout */
+ requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES)
+ .setExpectContinueEnabled(Boolean.TRUE)
+ .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
+ .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
+ .setConnectTimeout(Constants.HTTP_CONNECT_TIMEOUT).setSocketTimeout(Constants.SOCKET_TIMEOUT)
+ .setConnectionRequestTimeout(Constants.HTTP_CONNECTION_REQUEST_TIMEOUT).setRedirectsEnabled(true)
+ .build();
+ socketFactoryRegistry = RegistryBuilder.create()
+ .register("http", PlainConnectionSocketFactory.INSTANCE).register("https", socketFactory).build();
+ cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
+ cm.setDefaultMaxPerRoute(60);
+ cm.setMaxTotal(100);
+ }
- /**
- * get http request content
- * @param url url
- * @return http get request response content
- */
- public static String get(String url){
- CloseableHttpClient httpclient = HttpUtils.getInstance();
+ /**
+ * get http request content
+ *
+ * @param url url
+ * @return http get request response content
+ */
+ public static String get(String url) {
+ CloseableHttpClient httpclient = HttpUtils.getInstance();
- HttpGet httpget = new HttpGet(url);
- return getResponseContentString(httpget,httpclient);
+ HttpGet httpget = new HttpGet(url);
+ return getResponseContentString(httpget, httpclient);
}
/**
* get http response content
*
- * @param httpget httpget
+ * @param httpget httpget
* @param httpClient httpClient
* @return http get request response content
*/
public static String getResponseContentString(HttpGet httpget, CloseableHttpClient httpClient) {
- String responseContent = null;
- CloseableHttpResponse response = null;
- try {
- response = httpClient.execute(httpget);
- // check response status is 200
- if (response.getStatusLine().getStatusCode() == 200) {
- HttpEntity entity = response.getEntity();
- if (entity != null) {
- responseContent = EntityUtils.toString(entity, Constants.UTF_8);
- } else {
- logger.warn("http entity is null");
- }
- } else {
- logger.error("http get:{} response status code is not 200!", response.getStatusLine().getStatusCode());
- }
- } catch (IOException ioe) {
- logger.error(ioe.getMessage(), ioe);
- } finally {
- try {
- if (response != null) {
- EntityUtils.consume(response.getEntity());
- response.close();
- }
- } catch (IOException e) {
- logger.error(e.getMessage(), e);
- }
- if (!httpget.isAborted()) {
- httpget.releaseConnection();
- httpget.abort();
- }
-
- }
- return responseContent;
+ String responseContent = null;
+ CloseableHttpResponse response = null;
+ try {
+ response = httpClient.execute(httpget);
+ // check response status is 200
+ if (response.getStatusLine().getStatusCode() == 200) {
+ HttpEntity entity = response.getEntity();
+ if (entity != null) {
+ responseContent = EntityUtils.toString(entity, Constants.UTF_8);
+ } else {
+ logger.warn("http entity is null");
+ }
+ } else {
+ logger.error("http get:{} response status code is not 200!", response.getStatusLine().getStatusCode());
+ }
+ } catch (IOException ioe) {
+ logger.error(ioe.getMessage(), ioe);
+ } finally {
+ try {
+ if (response != null) {
+ EntityUtils.consume(response.getEntity());
+ response.close();
+ }
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ if (!httpget.isAborted()) {
+ httpget.releaseConnection();
+ httpget.abort();
+ }
+
+ }
+ return responseContent;
}
}
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/IOUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/IOUtils.java
index ce551d8405d3e2a5eeb274939c7510f356e8f00f..96366d539f2d7c35c3f0c2b34e07a4999b0b9487 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/IOUtils.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/IOUtils.java
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -18,14 +17,17 @@
package org.apache.dolphinscheduler.common.utils;
-
import java.io.Closeable;
import java.io.IOException;
public class IOUtils {
- public static void closeQuietly(Closeable closeable){
- if(closeable != null){
+ private IOUtils() {
+ throw new UnsupportedOperationException("Construct IOUtils");
+ }
+
+ public static void closeQuietly(Closeable closeable) {
+ if (closeable != null) {
try {
closeable.close();
} catch (IOException ignore) {
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/IpUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/IpUtils.java
index 858e5b44b587a98676380f1a69d0cf705578ca30..63d43e7b69de3b0ccb9cd3bfa0653227d89d8f7d 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/IpUtils.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/IpUtils.java
@@ -14,46 +14,50 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dolphinscheduler.common.utils;
+package org.apache.dolphinscheduler.common.utils;
/**
* http utils
*/
public class IpUtils {
- public static final String DOT = ".";
-
- /**
- * ip str to long
- *
- * @param ipStr ip string
- * @return ip to long
- */
- public static Long ipToLong(String ipStr) {
- String[] ipSet = ipStr.split("\\" + DOT);
-
- return Long.parseLong(ipSet[0]) << 24 | Long.parseLong(ipSet[1]) << 16 | Long.parseLong(ipSet[2]) << 8 | Long.parseLong(ipSet[3]);
- }
-
- /**
- * long to ip
- * @param ipLong the long number converted from IP
- * @return String
- */
- public static String longToIp(long ipLong) {
- long[] ipNumbers = new long[4];
- long tmp = 0xFF;
- ipNumbers[0] = ipLong >> 24 & tmp;
- ipNumbers[1] = ipLong >> 16 & tmp;
- ipNumbers[2] = ipLong >> 8 & tmp;
- ipNumbers[3] = ipLong & tmp;
-
- String sb = ipNumbers[0] + DOT +
- ipNumbers[1] + DOT +
- ipNumbers[2] + DOT +
- ipNumbers[3];
- return sb;
- }
+ private IpUtils() {
+ throw new UnsupportedOperationException("Construct IpUtils");
+ }
+
+ public static final String DOT = ".";
+
+ /**
+ * ip str to long
+ *
+ * @param ipStr ip string
+ * @return ip to long
+ */
+ public static Long ipToLong(String ipStr) {
+ String[] ipSet = ipStr.split("\\" + DOT);
+
+ return Long.parseLong(ipSet[0]) << 24 | Long.parseLong(ipSet[1]) << 16 | Long.parseLong(ipSet[2]) << 8 | Long.parseLong(ipSet[3]);
+ }
+
+ /**
+ * long to ip
+ *
+ * @param ipLong the long number converted from IP
+ * @return String
+ */
+ public static String longToIp(long ipLong) {
+ long[] ipNumbers = new long[4];
+ long tmp = 0xFF;
+ ipNumbers[0] = ipLong >> 24 & tmp;
+ ipNumbers[1] = ipLong >> 16 & tmp;
+ ipNumbers[2] = ipLong >> 8 & tmp;
+ ipNumbers[3] = ipLong & tmp;
+
+ return ipNumbers[0] + DOT
+ + ipNumbers[1] + DOT
+ + ipNumbers[2] + DOT
+ + ipNumbers[3];
+ }
}
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
index 3e88a84ec2afc7a95e4fbf1434c5d4e9dbef1560..56ef74d6ee2f2f1738c3a95aacee8b4dfac720f1 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
@@ -14,25 +14,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.dolphinscheduler.common.utils;
+import static com.fasterxml.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT;
+import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
+import static com.fasterxml.jackson.databind.DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL;
+import static com.fasterxml.jackson.databind.MapperFeature.REQUIRE_SETTERS_FOR_GETTERS;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.fasterxml.jackson.databind.type.CollectionType;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.*;
-
-import static com.fasterxml.jackson.databind.DeserializationFeature.*;
-import static com.fasterxml.jackson.databind.MapperFeature.REQUIRE_SETTERS_FOR_GETTERS;
/**
* json utils
@@ -49,13 +63,12 @@ public class JSONUtils {
.configure(ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
.configure(READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
.configure(REQUIRE_SETTERS_FOR_GETTERS, true)
- .setTimeZone(TimeZone.getDefault())
- ;
+ .setTimeZone(TimeZone.getDefault());
private JSONUtils() {
+ throw new UnsupportedOperationException("Construct JSONUtils");
}
-
public static ArrayNode createArrayNode() {
return objectMapper.createArrayNode();
}
@@ -94,9 +107,9 @@ public class JSONUtils {
* the fields of the specified object are generics, just the object itself should not be a
* generic type.
*
- * @param json the string from which the object is to be deserialized
+ * @param json the string from which the object is to be deserialized
* @param clazz the class of T
- * @param T
+ * @param T
* @return an object of type T from the string
* classOfT
*/
@@ -116,9 +129,9 @@ public class JSONUtils {
/**
* json to list
*
- * @param json json string
+ * @param json json string
* @param clazz class
- * @param T
+ * @param T
* @return list
*/
public static List toList(String json, Class clazz) {
@@ -137,7 +150,6 @@ public class JSONUtils {
return Collections.emptyList();
}
-
/**
* check json object valid
*
@@ -160,13 +172,12 @@ public class JSONUtils {
return false;
}
-
/**
* Method for finding a JSON Object field with specified name in this
* node or its child nodes, and returning value it has.
* If no matching field is found in this node or its descendants, returns null.
*
- * @param jsonNode json node
+ * @param jsonNode json node
* @param fieldName Name of field to look for
* @return Value of first matching node found, if any; null if none
*/
@@ -180,7 +191,6 @@ public class JSONUtils {
return node.toString();
}
-
/**
* json to map
*
@@ -195,7 +205,8 @@ public class JSONUtils {
}
try {
- return objectMapper.readValue(json, new TypeReference