diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
index f61fa5ef173..5390704c247 100644
--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
@@ -48,12 +47,12 @@ import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.TimeSource;
-import org.apache.solr.common.util.Utils;
import org.apache.solr.util.TimeOut;
import org.apache.zookeeper.KeeperException;
import org.junit.BeforeClass;
import org.junit.Test;
+import static java.util.Arrays.asList;
import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_DEF;
import static org.apache.solr.common.cloud.ZkStateReader.NRT_REPLICAS;
import static org.apache.solr.common.cloud.ZkStateReader.NUM_SHARDS_PROP;
@@ -191,14 +190,14 @@ public class CollectionsAPISolrJTest extends SolrCloudTestCase {
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
String nodeName = ((NamedList) response.getResponse().get("success")).getName(0);
- String corename = (String) ((NamedList) ((NamedList) response.getResponse().get("success")).getVal(0)).get("core");
+ String corename = (String) response.getResponse()._get(asList("success", nodeName,"core"),null);
try (HttpSolrClient coreclient = getHttpSolrClient(cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(nodeName))) {
CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreclient);
- Map m = status.getResponse().asMap(5);
- assertEquals(collectionName, Utils.getObjectByPath(m, true, Arrays.asList("status", corename, "cloud", "collection")));
- assertNotNull(Utils.getObjectByPath(m, true, Arrays.asList("status", corename, "cloud", "shard")));
- assertNotNull(Utils.getObjectByPath(m, true, Arrays.asList("status", corename, "cloud", "replica")));
+ NamedList m = status.getResponse();
+ assertEquals(collectionName, m._get(asList("status", corename, "cloud", "collection"), null));
+ assertNotNull(m._get(asList("status", corename, "cloud", "shard"), null));
+ assertNotNull(m._get(asList("status", corename, "cloud", "replica"), null));
}
}
diff --git a/solr/solrj/src/java/org/apache/solr/common/IteratorWriter.java b/solr/solrj/src/java/org/apache/solr/common/IteratorWriter.java
index cbfb58473ff..ec11c786d02 100644
--- a/solr/solrj/src/java/org/apache/solr/common/IteratorWriter.java
+++ b/solr/solrj/src/java/org/apache/solr/common/IteratorWriter.java
@@ -38,6 +38,15 @@ public interface IteratorWriter {
*/
ItemWriter add(Object o) throws IOException;
+ default ItemWriter addNoEx(Object o) {
+ try {
+ add(o);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return this;
+ }
+
default ItemWriter add(int v) throws IOException {
add((Integer) v);
return this;
diff --git a/solr/solrj/src/java/org/apache/solr/common/MapWriter.java b/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
index 9b1861a842d..3ec37e7a526 100644
--- a/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
+++ b/solr/solrj/src/java/org/apache/solr/common/MapWriter.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import org.apache.solr.common.util.Utils;
@@ -90,6 +91,25 @@ public interface MapWriter extends MapSerializable {
Object v = Utils.getObjectByPath(this, false, path);
return v == null ? def : v;
}
+ default void _forEachEntry(String path, BiConsumer fun) {
+ Utils.forEachMapEntry(this, path, fun);
+ }
+
+ default void _forEachEntry(BiConsumer fun) {
+ Utils.forEachMapEntry(this, null, fun);
+ }
+
+ /**
+ * Get a child object value using json path
+ *
+ * @param path the full path to that object such as ["a","b","c[4]","d"] etc
+ * @param def the default
+ * @return the found value or default
+ */
+ default Object _get(List path, Object def) {
+ Object v = Utils.getObjectByPath(this, false, path);
+ return v == null ? def : v;
+ }
/**
* An interface to push one entry at a time to the output.
* The order of the keys is not defined, but we assume they are distinct -- don't call {@code put} more than once
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java b/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java
index 16506028780..71cb78b5072 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java
@@ -16,6 +16,7 @@
*/
package org.apache.solr.common.util;
+import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
@@ -29,6 +30,7 @@ import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
+import org.apache.solr.common.MapWriter;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.MultiMapSolrParams;
import org.apache.solr.common.params.SolrParams;
@@ -59,7 +61,7 @@ import org.apache.solr.common.params.SolrParams;
*
*
*/
-public class NamedList implements Cloneable, Serializable, Iterable> {
+public class NamedList implements Cloneable, Serializable, Iterable> , MapWriter {
private static final long serialVersionUID = 1957981902839867821L;
protected final List