Browse Source

测试json反序列化为page

miemie 7 năm trước cách đây
mục cha
commit
3b271dc367

+ 2 - 1
build.gradle

@@ -32,7 +32,8 @@ ext {
         "junit"                             : "junit:junit:4.12",
         "mockito-all"                       : "org.mockito:mockito-all:1.10.19",
         "lombok"                            : "org.projectlombok:lombok:1.16.20",
-        "fastjson"                          : "com.alibaba:fastjson:1.2.37",
+        "fastjson"                          : "com.alibaba:fastjson:1.2.49",
+        "jackson"                           : "com.fasterxml.jackson.core:jackson-databind:2.9.6",
         "tomcatjdbc"                        : "org.apache.tomcat:tomcat-jdbc:9.0.2",
         //datasource
         "hikaricp"                          : "com.zaxxer:HikariCP:2.7.0",

+ 1 - 0
mybatis-plus/build.gradle

@@ -18,5 +18,6 @@ dependencies {
     testCompile rootProject.ext.dependencies["postgresql"]
     testCompile rootProject.ext.dependencies["oracle"]
     testCompile rootProject.ext.dependencies["mysql"]
+    testCompile rootProject.ext.dependencies["jackson"]
     testCompile 'ch.qos.logback:logback-classic:1.2.3'
 }

+ 11 - 4
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/SqlTest.java

@@ -1,14 +1,21 @@
 package com.baomidou.mybatisplus.test;
 
+import org.junit.Assert;
 import org.junit.Test;
 
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fasterxml.jackson.databind.ObjectMapper;
 
 public class SqlTest {
 
+    private final ObjectMapper mapper = new ObjectMapper();
+
     @Test
-    public void test() {
-        Stream.of(1, 2, 3, 4, 5).collect(Collectors.toList()).toArray();
+    public void testPageJsonDecode() throws Exception {
+        String json = "{\"current\":2,\"size\":9,\"ascs\":[\"name\",\"age\",\"qiuqiu\"]}";
+        Page page = mapper.readValue(json, Page.class);
+        Assert.assertEquals(2, page.getCurrent());
+        Assert.assertEquals(9, page.getSize());
+        Assert.assertEquals(3, page.ascs().length);
     }
 }