diff --git a/common/src/test/java/com/alibaba/nacos/common/utils/JacksonUtilsTest.java b/common/src/test/java/com/alibaba/nacos/common/utils/JacksonUtilsTest.java index 44e0f29ed..2aff441aa 100644 --- a/common/src/test/java/com/alibaba/nacos/common/utils/JacksonUtilsTest.java +++ b/common/src/test/java/com/alibaba/nacos/common/utils/JacksonUtilsTest.java @@ -37,7 +37,7 @@ import java.math.BigDecimal; import java.nio.charset.Charset; import java.util.Collections; import java.util.Date; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; @@ -435,7 +435,7 @@ public class JacksonUtilsTest { @Test public void testToJsonBytes() { - Map map = new HashMap(); + Map map = new LinkedHashMap(); map.put("string", "你好,中国!"); map.put("integer", 999); RestResult> restResult = new RestResult(); @@ -443,9 +443,8 @@ public class JacksonUtilsTest { byte[] bytes = JacksonUtils.toJsonBytes(restResult); String jsonFromBytes = ByteUtils.toString(bytes); - String expectedJson = "{\"code\":0,\"data\":{\"string\":\"你好,中国!\",\"integer\":999}}"; - Assert.assertEquals(expectedJson, jsonFromBytes); - + Assert.assertTrue(jsonFromBytes.contains("\"code\":0")); + Assert.assertTrue(jsonFromBytes.contains("\"data\":{\"string\":\"你好,中国!\",\"integer\":999}")); // old `toJsonBytes` method implementation: // public static byte[] toJsonBytes(Object obj) { // try { @@ -457,7 +456,9 @@ public class JacksonUtilsTest { // here is a verification to compare with the old implementation byte[] bytesFromOldImplementation = ByteUtils.toBytes(JacksonUtils.toJson(restResult)); - Assert.assertEquals(expectedJson, new String(bytesFromOldImplementation, Charset.forName(Constants.ENCODE))); + String jsonFromBytesOldImplementation = new String(bytesFromOldImplementation, Charset.forName(Constants.ENCODE)); + Assert.assertTrue(jsonFromBytesOldImplementation.contains("\"code\":0")); + Assert.assertTrue(jsonFromBytesOldImplementation.contains("\"data\":{\"string\":\"你好,中国!\",\"integer\":999}")); } @Test