use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_array_put method test_put_array_long.
public void test_put_array_long() throws Exception {
Map<String, Object> root = new HashMap<String, Object>();
root.put("values", new long[0]);
JSONPath path = new JSONPath("$.values");
path.arrayAdd(root, 123);
long[] array = (long[]) root.get("values");
Assert.assertEquals(1, array.length);
Assert.assertEquals(123, array[0]);
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_array_put method test_set.
public void test_set() throws Exception {
List<int[]> list = new ArrayList<int[]>();
list.add(new int[0]);
list.add(new int[0]);
JSONPath path = new JSONPath("$[0]");
path.arrayAdd(list, 123);
Assert.assertEquals(1, list.get(0).length);
Assert.assertEquals(123, ((int[]) list.get(0))[0]);
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_array_put method test_put_array_error_0.
public void test_put_array_error_0() throws Exception {
Exception error = null;
try {
JSONPath path = new JSONPath("$.values");
path.arrayAdd(new Object(), 123);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_array_put method test_set_2.
public void test_set_2() throws Exception {
Object[] list = new Object[2];
list[0] = new int[0];
list[0] = new int[0];
JSONPath path = new JSONPath("$[0]");
path.arrayAdd(list, 123);
Assert.assertEquals(1, ((int[]) list[0]).length);
Assert.assertEquals(123, ((int[]) list[0])[0]);
}
use of com.alibaba.fastjson.JSONPath in project fastjson by alibaba.
the class JSONPath_array_put method test_put_array_int.
public void test_put_array_int() throws Exception {
Map<String, Object> root = new HashMap<String, Object>();
root.put("values", new int[0]);
JSONPath path = new JSONPath("$.values");
path.arrayAdd(root, 123);
int[] array = (int[]) root.get("values");
Assert.assertEquals(1, array.length);
Assert.assertEquals(123, array[0]);
}
Aggregations