Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ void handleObjectProperty(String currentPath, Object model, EvaluationContextImp
PathRef pathRef = ctx.forUpdate() ? PathRef.create(model, property) : PathRef.NO_OP;
if (isLeaf()) {
String idx = "[" + String.valueOf(upstreamArrayIndex) + "]";
if(idx.equals("[-1]") || ctx.getRoot().getTail().prev().getPathFragment().equals(idx)){
if(idx.equals("[-1]") || ctx.getRoot().getTail().prev().getPathFragment().equals(idx) ||
ctx.getRoot().getTail().prev().getPathFragment().equals("[*]")){
ctx.addResult(evalPath, pathRef, propertyVal);
}
}
Expand Down
28 changes: 28 additions & 0 deletions json-path/src/test/java/com/jayway/jsonpath/Issue_857.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.jayway.jsonpath;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.junit.Assert;
import org.junit.Test;

/**
* @author skwqyg
* @Created on 2022 09 2022/9/10 16:36
*/
public class Issue_857 extends BaseTest{

@Test
public void test(){
Collection values = JsonPath.parse("[{\"key\":\"first value\"},{\"key\":\"second value\"}]")
.read("$..[*].key", java.util.Collection.class);
Assert.assertEquals(2,values.size());
Set<String> expect = new HashSet<>();
expect.add("first value");
expect.add("second value");
Assert.assertTrue(expect.containsAll(values));
System.out.println(values);
}

}