dsmiley commented on code in PR #3282:
URL: https://github.com/apache/solr/pull/3282#discussion_r2027550274


##########
solr/solrj/src/java/org/apache/solr/client/solrj/JacksonDataBindResponseParser.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Collection;
+import java.util.List;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SimpleOrderedMap;
+
+/** Parses JSON, deserializing to a domain type (class) via Jackson data-bind. 
*/
+public class JacksonDataBindResponseParser<T> extends ResponseParser {
+
+  private final Class<T> typeParam;
+
+  public JacksonDataBindResponseParser(Class<T> typeParam) {
+    this.typeParam = typeParam;
+  }
+
+  @Override
+  public String getWriterType() {
+    return "json";
+  }
+
+  @Override
+  public Collection<String> getContentTypes() {
+    return List.of("application/json");
+  }
+
+  // TODO it'd be nice if the ResponseParser could receive the mime type so it 
can parse
+  //  accordingly, maybe json, cbor, smile
+
+  @Override
+  public NamedList<Object> processResponse(InputStream stream, String 
encoding) throws IOException {

Review Comment:
   I would honestly hate to bring back a root type merely for error handling.  
Java has exceptions for this; let's use that instead.  We could make 
processResponse return whatever and for successful responses and throw 
something for the error case.  That's a bigger change than the scope of this 
PR, so WDYT about merging this without additional error handling?
   
   I propose a new JIRA issue (or your existing SOLR-17549 maybe) enhance the 
`ResponseParser` abstraction to take on the responsibility of error detection 
and throwing, and thus reducing some of the scope in the HTTP SolrClient side.  
I could imagine the processResponse method having more parameters including the 
HTTP status code, and using that to determine are we going to use data-bind or 
are we going to look for the error.  We'd need to do this for XML & JavaBin; 
finding a way to reuse some logic where it's similar.  Don't need to spec this 
out this second.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to