Issue #6558 - Allow configuring return type in JSON array parsing.

Updated JSON implementation to keep backward compatibility
by calling newArray(), now deprecated.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
(cherry picked from commit 1d542be610)
This commit is contained in:
Simone Bordet 2021-09-27 20:16:08 +02:00
parent 52f125f6d2
commit e9a47faeb3
1 changed files with 10 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.IntStream;
import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.TypeUtil;
@ -84,7 +85,7 @@ public class JSON
private final Map<String, Convertor> _convertors = new ConcurrentHashMap<>();
private int _stringBufferSize = 1024;
private Function<List<?>, Object> _arrayConverter = List::toArray;
private Function<List<?>, Object> _arrayConverter = this::defaultArrayConverter;
/**
* @return the initial stringBuffer size to use when creating JSON strings
@ -937,6 +938,14 @@ public class JSON
return map;
}
private Object defaultArrayConverter(List<?> list)
{
// Call newArray() to keep backward compatibility.
Object[] objects = newArray(list.size());
IntStream.range(0, list.size()).forEach(i -> objects[i] = list.get(i));
return objects;
}
protected Object parseArray(Source source)
{
if (source.next() != '[')