Skip to content

Commit

Permalink
fix: List NPE.
Browse files Browse the repository at this point in the history
  • Loading branch information
myoss committed Nov 7, 2020
1 parent 8fef268 commit d5c9d98
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -229,7 +231,7 @@ public static class ModelValueDeserializer implements ObjectDeserializer {
@Override
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONArray jsonArray = (JSONArray) parser.parse();
if (jsonArray == null) {
if (CollectionUtils.isEmpty(jsonArray)) {
return null;
}
List<Order> orders = new ArrayList<>(jsonArray.size());
Expand Down Expand Up @@ -257,6 +259,9 @@ public static class ModelValueJsonAdapter implements JsonDeserializer<Sort>, 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<Order> orders = new ArrayList<>(jsonArray.size());
for (JsonElement o : jsonArray) {
JsonObject item = o.getAsJsonObject();
Expand Down Expand Up @@ -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<Order> orders = new ArrayList<>(node.size());
for (JsonNode json : node) {
Order order = new Order(Direction.valueOf(json.get("direction").asText()),
Expand Down

0 comments on commit d5c9d98

Please sign in to comment.