Replace fastjson with jackson for naming.Cluster
This commit is contained in:
parent
db6fc0c026
commit
5c8ccfde0f
@ -15,11 +15,12 @@
|
||||
*/
|
||||
package com.alibaba.nacos.naming.core;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.nacos.naming.healthcheck.HealthCheckReactor;
|
||||
import com.alibaba.nacos.naming.healthcheck.HealthCheckStatus;
|
||||
import com.alibaba.nacos.naming.healthcheck.HealthCheckTask;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.util.Assert;
|
||||
@ -43,19 +44,19 @@ public class Cluster extends com.alibaba.nacos.api.naming.pojo.Cluster implement
|
||||
|
||||
private int defIPPort = -1;
|
||||
|
||||
@JSONField(serialize = false)
|
||||
@JsonIgnore
|
||||
private HealthCheckTask checkTask;
|
||||
|
||||
@JSONField(serialize = false)
|
||||
@JsonIgnore
|
||||
private Set<Instance> persistentInstances = new HashSet<>();
|
||||
|
||||
@JSONField(serialize = false)
|
||||
@JsonIgnore
|
||||
private Set<Instance> ephemeralInstances = new HashSet<>();
|
||||
|
||||
@JSONField(serialize = false)
|
||||
@JsonIgnore
|
||||
private Service service;
|
||||
|
||||
@JSONField(serialize = false)
|
||||
@JsonIgnore
|
||||
private volatile boolean inited = false;
|
||||
|
||||
private Map<String, String> metadata = new ConcurrentHashMap<>();
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.naming.core;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
|
||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -27,6 +27,7 @@ import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@ -120,8 +121,9 @@ public class ClusterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeToJson() {
|
||||
String actual = JSON.toJSONString(cluster);
|
||||
public void testSerialize() throws Exception {
|
||||
String actual = JacksonUtils.toJson(cluster);
|
||||
System.out.println(actual);
|
||||
assertTrue(actual.contains("\"defaultPort\":80"));
|
||||
assertTrue(actual.contains("\"defIPPort\":8080"));
|
||||
assertTrue(actual.contains("\"healthChecker\":{\"type\":\"TCP\"}"));
|
||||
@ -136,4 +138,21 @@ public class ClusterTest {
|
||||
assertFalse(actual.contains("\"service\""));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws Exception {
|
||||
String example = "{\"defCkport\":80,\"defIPPort\":8080,\"defaultCheckPort\":80,\"defaultPort\":80,\"empty\":true,\"healthChecker\":{\"type\":\"TCP\"},\"metadata\":{},\"name\":\"nacos-cluster-1\",\"serviceName\":\"nacos.service.1\",\"sitegroup\":\"\",\"useIPPort4Check\":true}";
|
||||
Cluster actual = JacksonUtils.toObj(example, Cluster.class);
|
||||
assertEquals(80, actual.getDefCkport());
|
||||
assertEquals(8080, actual.getDefIPPort());
|
||||
assertEquals(80, actual.getDefaultCheckPort());
|
||||
assertEquals(80, actual.getDefaultPort());
|
||||
assertTrue(actual.isEmpty());
|
||||
assertTrue(actual.getMetadata().isEmpty());
|
||||
assertTrue(actual.isUseIPPort4Check());
|
||||
assertEquals("nacos-cluster-1", actual.getName());
|
||||
assertEquals("nacos.service.1", actual.getServiceName());
|
||||
assertEquals("", actual.getSitegroup());
|
||||
assertNull(actual.getHealthCheckTask());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user