Skip to content

Commit

Permalink
fix remove TODO exception for issue #3192
Browse files Browse the repository at this point in the history
  • Loading branch information
yanxutao89 committed Dec 5, 2024
1 parent 0293061 commit 99b8ef8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 0 additions & 3 deletions core/src/main/java/com/alibaba/fastjson2/JSONPathSegment.java
Original file line number Diff line number Diff line change
Expand Up @@ -1285,10 +1285,7 @@ public void accept(JSONReader jsonReader, JSONPath.Context context) {
context.value = values;
}
context.eval = true;
return;
}

throw new JSONException("TODO");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.alibaba.fastjson2.issues_3100;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONPath;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue3192 {
@Test
public void test_jsonpath_array() {
String json = "{ \"array\": null }";
assertEquals("[]", JSON.toJSONString(JSONPath.extract(json, "$.array[0].key", JSONPath.Feature.KeepNullValue, JSONPath.Feature.AlwaysReturnList)));
assertEquals("[]", JSON.toJSONString(JSONPath.extract(json, "$.array[*].key", JSONPath.Feature.KeepNullValue, JSONPath.Feature.AlwaysReturnList)));

json = "{ \"array\": [{\"key\":1}, {\"key\":null}, {\"key\":3}] }";
assertEquals("[1]", JSON.toJSONString(JSONPath.extract(json, "$.array[0].key", JSONPath.Feature.KeepNullValue, JSONPath.Feature.AlwaysReturnList)));
assertEquals("[1,null,3]", JSON.toJSONString(JSONPath.extract(json, "$.array[*].key", JSONPath.Feature.KeepNullValue, JSONPath.Feature.AlwaysReturnList)));
}
}

0 comments on commit 99b8ef8

Please sign in to comment.