mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix add bug
This commit is contained in:
@@ -449,7 +449,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
*/
|
||||
@Override
|
||||
public Object set(int index, Object element) {
|
||||
if(index > size()){
|
||||
if(index >= size()){
|
||||
add(index, element);
|
||||
}
|
||||
return this.rawList.set(index, JSONUtil.wrap(element, this.config));
|
||||
|
@@ -217,6 +217,15 @@ public class JSONArrayTest {
|
||||
Assert.assertEquals(4, jsonArray.size());
|
||||
}
|
||||
|
||||
// https://github.com/dromara/hutool/issues/1858
|
||||
@Test
|
||||
public void putTest2(){
|
||||
final JSONArray jsonArray = new JSONArray();
|
||||
jsonArray.put(0, 1);
|
||||
Assert.assertEquals(1, jsonArray.size());
|
||||
Assert.assertEquals(1, jsonArray.get(0));
|
||||
}
|
||||
|
||||
private static Map<String, String> buildMap(String id, String parentId, String name) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
|
Reference in New Issue
Block a user