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


##########
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 {
+    // TODO generalize to CBOR, Smile, ...
+    var mapper = JacksonContentWriter.DEFAULT_MAPPER;
+
+    final T parsedVal;
+    if (encoding == null) {
+      parsedVal = mapper.readValue(stream, typeParam);
+    } else {
+      parsedVal = mapper.readValue(new InputStreamReader(stream, encoding), 
typeParam);
+    }
+
+    return SimpleOrderedMap.of("response", parsedVal);

Review Comment:
   Ah; good catch!  Hmm.  It'd be good to induce an error in a test using this 
API so we can verify that whatever we want to happen, actually happens.  I 
would personally rather prefer that become a new evolutionary issue/PR rather 
than increasing the scope of this one.  I could see us making bigger changes to 
accommodate that concern.  I'll expand on that in the other comment...



-- 
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