Skip to content

Commit

Permalink
Merge pull request #2947 from KomachiSion/develop-issue#2842
Browse files Browse the repository at this point in the history
[ISSUE #2842] Replace all fastjson with jackson
  • Loading branch information
yanlinly committed Jun 3, 2020
2 parents 5d9c079 + 74a2995 commit 7ac0ff8
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 269 deletions.
20 changes: 1 addition & 19 deletions distribution/LICENSE-BIN
Expand Up @@ -245,24 +245,6 @@ The source code of slf4j can be found at https://github.com/qos-ch/slf4j.
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

------
This product has a bundle fastjson, which is available under the ASL2 License.
The source code of fastjson can be found at https://github.com/alibaba/fastjson.

Copyright 1999-2016 Alibaba Group Holding Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

------
This product has a bundle javassist, which is available under the ASL2 License.
The source code of javassist can be found at https://github.com/jboss-javassist/javassist.
Expand Down Expand Up @@ -301,7 +283,7 @@ The source code of jna can be found at https://github.com/java-native-access/jna
This product has a bundle guava, which is available under the ASL2 License.
The source code of guava can be found at https://github.com/google/guava.

Copyright (C) 2007 The Guava authors
Copyright (C) 2007 The Guava authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
8 changes: 0 additions & 8 deletions pom.xml
Expand Up @@ -125,7 +125,6 @@

<!-- dependency version -->
<spring-boot-dependencies.version>2.1.1.RELEASE</spring-boot-dependencies.version>
<fastjson.version>1.2.58</fastjson.version>
<servlet-api.version>3.0</servlet-api.version>
<commons-lang.version>2.6</commons-lang.version>
<commons-lang3.version>3.4</commons-lang3.version>
Expand Down Expand Up @@ -618,13 +617,6 @@
<version>${project.version}</version>
</dependency>

<!-- Alibaba libs-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions test/pom.xml
Expand Up @@ -52,11 +52,6 @@
<artifactId>truth</artifactId>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>nacos-api</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions test/src/test/java/com/alibaba/nacos/test/BaseTest.java
Expand Up @@ -16,7 +16,7 @@

package com.alibaba.nacos.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.naming.healthcheck.RsInfo;
import org.junit.Test;

Expand All @@ -32,7 +32,7 @@ public class BaseTest {
@Test
public void test_rs_json() {
String json = "{\"cluster\":\"DEFAULT\",\"ip\":\"127.0.0.1\",\"metadata\":{},\"port\":60000,\"scheduled\":true,\"serviceName\":\"DEFAULT_GROUP@@jinhan9J7ye.Vj6hx.net\",\"weight\":1.0}";
RsInfo client = JSON.parseObject(json, RsInfo.class);
RsInfo client = JacksonUtils.toObj(json, RsInfo.class);
System.out.println(client);
}

Expand Down
Expand Up @@ -16,11 +16,11 @@

package com.alibaba.nacos.test.common;

import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.common.http.HttpUtils;
import com.alibaba.nacos.common.http.handler.ResponseHandler;
import com.alibaba.nacos.common.http.param.Query;
import com.alibaba.nacos.common.model.RestResult;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.core.utils.ClassUtils;
import com.alibaba.nacos.core.utils.GenericType;
import org.junit.Assert;
Expand All @@ -44,7 +44,7 @@ public class HttpUtils_ITCase {

@Test
public void test_deserialization_type() throws Exception {
String json = JSON.toJSONString(list);
String json = JacksonUtils.toJson(list);
ArrayList<Integer> tmp = ResponseHandler.convert(json, new GenericType<List<Integer>>(){}.getType());
Assert.assertEquals(list, tmp);
}
Expand All @@ -58,7 +58,7 @@ public void test_rest_result() throws Exception {

@Test
public void test_deserialization_class() throws Exception {
String json = JSON.toJSONString(list);
String json = JacksonUtils.toJson(list);
ArrayList<Integer> tmp = ResponseHandler.convert(json, ClassUtils.resolveGenericType(new GenericType<List<Integer>>(){}.getClass()));
Assert.assertEquals(list, tmp);
}
Expand Down
Expand Up @@ -15,7 +15,6 @@
*/
package com.alibaba.nacos.test.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.Nacos;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
Expand All @@ -28,6 +27,7 @@
import com.alibaba.nacos.client.config.http.MetricsHttpAgent;
import com.alibaba.nacos.client.config.http.ServerHttpAgent;
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.common.utils.ThreadUtils;
import org.junit.After;
import org.junit.Assert;
Expand Down Expand Up @@ -84,7 +84,7 @@ public void cleanup() throws Exception {
List<String> params = Arrays.asList("dataId", dataId, "group", group, "beta", "true");
result = agent.httpDelete(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
Assert.assertEquals(true, JSON.parseObject(result.content).getBoolean("data"));
Assert.assertTrue(JacksonUtils.toObj(result.content).get("data").booleanValue());
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
Expand Down Expand Up @@ -660,7 +660,7 @@ public void nacos_openAPI_detailConfig_1() {
result = agent.httpGet(CONFIG_CONTROLLER_PATH, null, params, agent.getEncode(), TIME_OUT);
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);

Assert.assertEquals(content, JSON.parseObject(result.content).getString("content"));
Assert.assertEquals(content, JacksonUtils.toObj(result.content).get("content").textValue());
} catch (Exception e) {
Assert.fail();
}
Expand Down Expand Up @@ -688,7 +688,7 @@ public void nacos_openAPI_catalog() {
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);

System.out.println(result.content);
Assert.assertNotNull(JSON.parseObject(result.content).getString("data"));
Assert.assertFalse(JacksonUtils.toObj(result.content).get("data").isNull());

} catch (Exception e) {
Assert.fail();
Expand Down Expand Up @@ -717,7 +717,7 @@ public void nacos_openAPI_queryBeta_1() {
List<String> params = Arrays.asList("dataId", dataId, "group", group, "beta", "true");
result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
Assert.assertEquals(content, JSON.parseObject(result.content).getJSONObject("data").getString("content"));
Assert.assertEquals(content, JacksonUtils.toObj(result.content).get("data").get("content").textValue());
// delete data
result = agent.httpDelete(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
Expand Down Expand Up @@ -751,7 +751,7 @@ public void nacos_openAPI_queryBeta_delete() {
result = agent.httpDelete(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);

Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
Assert.assertEquals(true, JSON.parseObject(result.content).getBoolean("data"));
Assert.assertTrue(JacksonUtils.toObj(result.content).get("data").booleanValue());
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
Expand Down Expand Up @@ -780,8 +780,8 @@ public void nacos_openAPI_fuzzySearchConfig() {
result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);

Assert.assertTrue(JSON.parseObject(result.content).getIntValue("totalCount") >= 1);
Assert.assertTrue(JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content").startsWith(content));
Assert.assertTrue(JacksonUtils.toObj(result.content).get("totalCount").intValue() >= 1);
Assert.assertTrue(JacksonUtils.toObj(result.content).get("pageItems").get(0).get("content").textValue().startsWith(content));
} catch (Exception e) {
Assert.fail();
}
Expand Down Expand Up @@ -809,8 +809,8 @@ public void nacos_openAPI_fuzzySearchConfig_1() {
result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);

Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
Assert.assertTrue(JSON.parseObject(result.content).getIntValue("totalCount") >= 1);
Assert.assertEquals(content, JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content"));
Assert.assertTrue(JacksonUtils.toObj(result.content).get("totalCount").intValue() >= 1);
Assert.assertEquals(content, JacksonUtils.toObj(result.content).get("pageItems").get(0).get("content").textValue());

} catch (Exception e) {
Assert.fail();
Expand Down Expand Up @@ -839,8 +839,8 @@ public void nacos_openAPI_searchConfig() {
result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);

Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
Assert.assertEquals(1, JSON.parseObject(result.content).getIntValue("totalCount"));
Assert.assertEquals(content, JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content"));
Assert.assertEquals(1, JacksonUtils.toObj(result.content).get("totalCount").intValue());
Assert.assertEquals(content, JacksonUtils.toObj(result.content).get("pageItems").get(0).get("content").textValue());

} catch (Exception e) {
Assert.fail();
Expand Down Expand Up @@ -868,8 +868,8 @@ public void nacos_openAPI_searchConfig_2() {
List<String> params = Arrays.asList("dataId", dataId, "group", group, "pageNo","1", "pageSize","10", "search", "accurate");
result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, "utf-8", TIME_OUT);
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
Assert.assertEquals(1, JSON.parseObject(result.content).getIntValue("totalCount"));
Assert.assertEquals(content, JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content"));
Assert.assertEquals(1, JacksonUtils.toObj(result.content).get("totalCount").intValue());
Assert.assertEquals(content, JacksonUtils.toObj(result.content).get("pageItems").get(0).get("content").textValue());
} catch (Exception e) {
Assert.fail();
}
Expand Down
Expand Up @@ -16,11 +16,9 @@

package com.alibaba.nacos.test.config;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.Nacos;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.core.utils.ApplicationUtils;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.test.base.Params;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -38,8 +36,6 @@
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponentsBuilder;

import java.util.concurrent.CountDownLatch;

/**
* @author xiaochun.xxc
* @date 2019-07-03
Expand Down Expand Up @@ -151,7 +147,7 @@ public void publishBetaConfig_noBetaIps_beta() throws Exception {
String.class,
HttpMethod.GET);
Assert.assertTrue(response1.getStatusCode().is2xxSuccessful());
Assert.assertEquals(null, JSONObject.parseObject(response1.getBody()).getString("data"));
Assert.assertTrue(JacksonUtils.toObj(response1.getBody()).get("data").isNull());
}

/**
Expand Down Expand Up @@ -228,7 +224,7 @@ public void getBetaConfig() throws Exception {
String.class,
HttpMethod.GET);
Assert.assertTrue(response1.getStatusCode().is2xxSuccessful());
Assert.assertEquals("com.dungu.test", JSONObject.parseObject(response1.getBody()).getJSONObject("data").getString("dataId"));
Assert.assertEquals("com.dungu.test", JacksonUtils.toObj(response1.getBody()).get("data").get("dataId").asText());
}

/**
Expand Down Expand Up @@ -265,7 +261,7 @@ public void deleteBetaConfig() throws Exception {
String.class,
HttpMethod.GET);
Assert.assertTrue(response1.getStatusCode().is2xxSuccessful());
Assert.assertEquals("com.dungu.test", JSONObject.parseObject(response1.getBody()).getJSONObject("data").getString("dataId"));
Assert.assertEquals("com.dungu.test", JacksonUtils.toObj(response1.getBody()).get("data").get("dataId").asText());

ResponseEntity<String> response2 = request(CONFIG_CONTROLLER_PATH + "/configs?beta=true",
Params.newParams()
Expand All @@ -276,7 +272,7 @@ public void deleteBetaConfig() throws Exception {
String.class,
HttpMethod.DELETE);
Assert.assertTrue(response2.getStatusCode().is2xxSuccessful());
Assert.assertEquals("true", JSONObject.parseObject(response2.getBody()).getString("data"));
Assert.assertEquals("true", JacksonUtils.toObj(response2.getBody()).get("data").asText());

ResponseEntity<String> response3 = request(CONFIG_CONTROLLER_PATH + "/configs?beta=true",
Params.newParams()
Expand All @@ -287,7 +283,7 @@ public void deleteBetaConfig() throws Exception {
String.class,
HttpMethod.GET);
Assert.assertTrue(response3.getStatusCode().is2xxSuccessful());
Assert.assertEquals(null, JSONObject.parseObject(response3.getBody()).getString("data"));
Assert.assertTrue(JacksonUtils.toObj(response3.getBody()).get("data").isNull());
}


Expand Down Expand Up @@ -325,7 +321,7 @@ public void deleteBetaConfig_delete_beta_false() throws Exception {
String.class,
HttpMethod.GET);
Assert.assertTrue(response1.getStatusCode().is2xxSuccessful());
Assert.assertEquals("com.dungu.test", JSONObject.parseObject(response1.getBody()).getJSONObject("data").getString("dataId"));
Assert.assertEquals("com.dungu.test", JacksonUtils.toObj(response1.getBody()).get("data").get("dataId").asText());

ResponseEntity<String> response2 = request(CONFIG_CONTROLLER_PATH + "/configs?beta=false",
Params.newParams()
Expand All @@ -347,7 +343,7 @@ public void deleteBetaConfig_delete_beta_false() throws Exception {
String.class,
HttpMethod.GET);
Assert.assertTrue(response3.getStatusCode().is2xxSuccessful());
Assert.assertEquals("com.dungu.test", JSONObject.parseObject(response3.getBody()).getJSONObject("data").getString("dataId"));
Assert.assertEquals("com.dungu.test", JacksonUtils.toObj(response3.getBody()).get("data").get("dataId").asText());
}

<T> ResponseEntity<T> request(String path, MultiValueMap<String, String> params, Class<T> clazz, HttpMethod httpMethod) {
Expand Down

0 comments on commit 7ac0ff8

Please sign in to comment.