Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
bug fixed for jsonpath. issue #1030
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Mar 13, 2017
1 parent 7a12763 commit be15615
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/alibaba/fastjson/JSONPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public Object eval(Object rootObject) {

Object currentObject = rootObject;
for (int i = 0; i < segments.length; ++i) {
currentObject = segments[i].eval(this, rootObject, currentObject);
Segement segement = segments[i];
currentObject = segement.eval(this, rootObject, currentObject);
}
return currentObject;
}
Expand Down Expand Up @@ -2155,7 +2156,12 @@ protected Object getPropertyValue(final Object currentObject, final String prope
for (int i = 0; i < list.size(); ++i) {
Object obj = list.get(i);
Object itemValue = getPropertyValue(obj, propertyName, strictMode);
fieldValues.add(itemValue);
if (itemValue instanceof Collection) {
Collection collection = (Collection) itemValue;
fieldValues.addAll(collection);
} else {
fieldValues.add(itemValue);
}
}

return fieldValues;
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/alibaba/json/bvt/bug/Issue1030.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.alibaba.json.bvt.bug;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import junit.framework.TestCase;

import java.util.List;

/**
* Created by wenshao on 13/03/2017.
*/
public class Issue1030 extends TestCase {
public void test_for_issue() throws Exception {
String DOC = "{\"books\":[{\"pageWords\":[{\"num\":10},{\"num\":15}]},{\"pageWords\":[{\"num\":20}]}]}";

//fastjson包
JSONObject result = JSONObject.parseObject(DOC);

List array = (List) JSONPath.eval(result, "$.books[0:].pageWords[0:]");

assertEquals(3, array.size());
}
}

0 comments on commit be15615

Please sign in to comment.