Skip to content

Commit

Permalink
fix support Queue for JSONPathSegmentIndex.eval, for issue #2602
Browse files Browse the repository at this point in the history
  • Loading branch information
yanxutao89 authored and wenshao committed May 21, 2024
1 parent 0452685 commit 32d0dcc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void eval(JSONPath.Context context) {
return;
}

if ((object instanceof SortedSet || object instanceof LinkedHashSet)
if ((object instanceof SortedSet || object instanceof LinkedHashSet || object instanceof Queue)
|| (index == 0 && object instanceof Collection && ((Collection<?>) object).size() == 1)
) {
Collection collection = (Collection) object;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.alibaba.fastjson2.issues_2600;

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

import java.util.ArrayList;
import java.util.concurrent.ConcurrentLinkedQueue;

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

public class Issue2602 {
@Test
public void test() {
String json = "[{\"a\":998982405},{\"a\":998992165},{\"$ref\":\"$[1]\"}]";
ArrayList list = JSON.parseObject(json, new TypeReference<ArrayList>() {
}.getType());
ConcurrentLinkedQueue queue = JSON.parseObject(json, new TypeReference<ConcurrentLinkedQueue>() {
}.getType());
assertEquals(list.get(0), queue.poll());
assertEquals(list.get(1), queue.poll());
assertEquals(list.get(2), queue.poll());
}
}

0 comments on commit 32d0dcc

Please # to comment.