Skip to content

Commit

Permalink
Issue #6558 - Allow configuring return type in JSON array parsing.
Browse files Browse the repository at this point in the history
Updated JSON implementation to keep backward compatibility
by calling newArray(), now deprecated.

Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed Sep 27, 2021
1 parent 992f9a5 commit 1d542be
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.IntStream;

import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.Loader;
Expand Down Expand Up @@ -97,7 +98,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;

public JSON()
{
Expand Down Expand Up @@ -1070,6 +1071,14 @@ protected Object parseObject(Source source)
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() != '[')
Expand Down

0 comments on commit 1d542be

Please sign in to comment.