From 54398090f56fcb17e3a08f5587d72f9bb27683c0 Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Thu, 28 May 2020 17:12:57 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E5=85=A5=E5=8F=82=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E4=B8=BA=E6=95=B0=E7=BB=84=EF=BC=8C=E5=85=B6=E4=B8=AD?= =?UTF-8?q?=E5=8C=85=E5=90=ABnull,=E5=88=99id=E6=95=B0=E7=BB=84=E7=94=A8nu?= =?UTF-8?q?ll=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/dispose/pojo/vo/common/IDArrayReq.java | 8 ++++++-- src/test/java/com/dispose/test/debug/demo.java | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/dispose/pojo/vo/common/IDArrayReq.java b/src/main/java/com/dispose/pojo/vo/common/IDArrayReq.java index 9b113d26..10a96df6 100644 --- a/src/main/java/com/dispose/pojo/vo/common/IDArrayReq.java +++ b/src/main/java/com/dispose/pojo/vo/common/IDArrayReq.java @@ -30,8 +30,10 @@ public class IDArrayReq { public void setId(String[] id) { List idList = Arrays.asList(id); - if(idList.contains("")) { + if (idList.contains("")) { this.id = new String[]{""}; + } else if (idList.contains(null)) { + this.id = null; } else { Map ret = idList.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); System.out.println(ret); @@ -44,8 +46,10 @@ public class IDArrayReq { public void setTaskId(String[] taskId) { List idList = Arrays.asList(taskId); - if(idList.contains("")) { + if (idList.contains("")) { this.taskId = new String[]{""}; + } else if (idList.contains(null)) { + this.taskId = null; } else { Map ret = idList.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); System.out.println(ret); diff --git a/src/test/java/com/dispose/test/debug/demo.java b/src/test/java/com/dispose/test/debug/demo.java index f2c74531..d3490f3f 100644 --- a/src/test/java/com/dispose/test/debug/demo.java +++ b/src/test/java/com/dispose/test/debug/demo.java @@ -16,13 +16,19 @@ public class demo { String json = "{\"id\":[\"1\", \"123\", \"1234\", \"1234\"]}"; String json2 = "{\"id\":[\"1\", \"123\", \"1234\"]}"; String json3 = "{\"id\":[\"\", \"1\", \"123\", \"1234\"]}"; + String json4 = "{\"id\":[\"1\", \"123\", \"1234\", null]}"; IDArrayReq id = new ObjectMapper().readValue(json3, IDArrayReq.class); Assert.assertEquals(id.getId().length, 1); + id = new ObjectMapper().readValue(json2, IDArrayReq.class); Assert.assertEquals(id.getId().length, 3); + id = new ObjectMapper().readValue(json, IDArrayReq.class); Assert.assertEquals(id.getId().length, 3); + + id = new ObjectMapper().readValue(json4, IDArrayReq.class); + Assert.assertEquals(id.getId().length, 1); } }