bug fixed for references. for jsonarray ref compute error.

This commit is contained in:
wenshao
2016-10-20 09:23:20 +08:00
parent e6ff114721
commit 3eaeea86f6
2 changed files with 23 additions and 0 deletions
@@ -467,6 +467,12 @@ public class DefaultJSONParser implements Closeable {
: lexer.text.charAt(index));
}
ArrayList list = new ArrayList();
final boolean parentIsArray = fieldName != null && fieldName.getClass() == Integer.class;
if (!parentIsArray) {
this.setContext(context);
}
this.parseArray(list, key);
value = new JSONArray(list);
if (innerMap != null) {
@@ -0,0 +1,17 @@
package com.alibaba.json.bvt.ref;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import junit.framework.TestCase;
/**
* Created by wenshao on 16/8/23.
*/
public class RefTest22 extends TestCase {
public void test_ref() throws Exception {
String json = "{\"name\":\"123\",\"assetSize\":{},\"items\":[{\"id\":123}],\"refItems\":{\"$ref\":\"$.items[0]\"}}";
JSONObject root = JSON.parseObject(json);
assertSame(root.getJSONArray("items").get(0), root.getJSONObject("refItems"));
}
}