From d5c9d98e4da5c8218f4d2fe202bee41ef883f019 Mon Sep 17 00:00:00 2001 From: "Jerry.Chen" Date: Sat, 7 Nov 2020 19:24:37 +0800 Subject: [PATCH] fix: List NPE. --- .../main/java/app/myoss/cloud/core/lang/dto/Sort.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/myoss-starter-core/src/main/java/app/myoss/cloud/core/lang/dto/Sort.java b/myoss-starter-core/src/main/java/app/myoss/cloud/core/lang/dto/Sort.java index c4092fa..dbec9af 100644 --- a/myoss-starter-core/src/main/java/app/myoss/cloud/core/lang/dto/Sort.java +++ b/myoss-starter-core/src/main/java/app/myoss/cloud/core/lang/dto/Sort.java @@ -25,6 +25,8 @@ import java.util.Iterator; import java.util.List; +import org.springframework.util.CollectionUtils; + import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.annotation.JSONField; @@ -229,7 +231,7 @@ public static class ModelValueDeserializer implements ObjectDeserializer { @Override public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { JSONArray jsonArray = (JSONArray) parser.parse(); - if (jsonArray == null) { + if (CollectionUtils.isEmpty(jsonArray)) { return null; } List orders = new ArrayList<>(jsonArray.size()); @@ -257,6 +259,9 @@ public static class ModelValueJsonAdapter implements JsonDeserializer, Jso public Sort deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonArray jsonArray = json.getAsJsonArray(); + if (jsonArray == null || jsonArray.size() == 0) { + return null; + } List orders = new ArrayList<>(jsonArray.size()); for (JsonElement o : jsonArray) { JsonObject item = o.getAsJsonObject(); @@ -284,6 +289,9 @@ public static class ModelValueJacksonDeserializer extends com.fasterxml.jackson. public Sort deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException { ArrayNode node = jsonParser.getCodec().readTree(jsonParser); + if (node == null || node.size() == 0) { + return null; + } List orders = new ArrayList<>(node.size()); for (JsonNode json : node) { Order order = new Order(Direction.valueOf(json.get("direction").asText()),