|
|
@ -56,7 +56,12 @@ public abstract class AbstractJsonProvider implements JsonProvider { |
|
|
|
if (!isArray(array)) { |
|
|
|
if (!isArray(array)) { |
|
|
|
throw new UnsupportedOperationException(); |
|
|
|
throw new UnsupportedOperationException(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
((List) array).set(index, newValue); |
|
|
|
List l = (List) array; |
|
|
|
|
|
|
|
if (index == l.size()){ |
|
|
|
|
|
|
|
l.add(newValue); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
l.set(index, newValue); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -78,10 +83,10 @@ public abstract class AbstractJsonProvider implements JsonProvider { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets a value in an object or array |
|
|
|
* Sets a value in an object |
|
|
|
* |
|
|
|
* |
|
|
|
* @param obj an array or an object |
|
|
|
* @param obj an object |
|
|
|
* @param key a String key or a numerical index |
|
|
|
* @param key a String key |
|
|
|
* @param value the value to set |
|
|
|
* @param value the value to set |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
@ -89,14 +94,7 @@ public abstract class AbstractJsonProvider implements JsonProvider { |
|
|
|
if (isMap(obj)) |
|
|
|
if (isMap(obj)) |
|
|
|
((Map) obj).put(key.toString(), value); |
|
|
|
((Map) obj).put(key.toString(), value); |
|
|
|
else { |
|
|
|
else { |
|
|
|
List list = (List) obj; |
|
|
|
throw new JsonPathException("setProperty operation cannot be used with " + obj!=null?obj.getClass().getName():"null"); |
|
|
|
int index; |
|
|
|
|
|
|
|
if (key != null) { |
|
|
|
|
|
|
|
index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
index = list.size(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
list.add(index, value); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -159,7 +157,7 @@ public abstract class AbstractJsonProvider implements JsonProvider { |
|
|
|
} else if(obj instanceof String){ |
|
|
|
} else if(obj instanceof String){ |
|
|
|
return ((String)obj).length(); |
|
|
|
return ((String)obj).length(); |
|
|
|
} |
|
|
|
} |
|
|
|
throw new JsonPathException("length operation can not applied to " + obj!=null?obj.getClass().getName():"null"); |
|
|
|
throw new JsonPathException("length operation cannot be applied to " + obj!=null?obj.getClass().getName():"null"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|