Huaping Gu created SOLR-10364:
---------------------------------

             Summary: Solr bean binding only support List and Map?
                 Key: SOLR-10364
                 URL: https://issues.apache.org/jira/browse/SOLR-10364
             Project: Solr
          Issue Type: Bug
      Security Level: Public (Default Security Level. Issues are Public)
          Components: SolrJ
    Affects Versions: 6.4.2, 4.10.4
            Reporter: Huaping Gu
             Fix For: 4.10.4


In class DocumentObjectBinder.java, when jnject a value from doc to bean class, 
seems it only support List and Map, and not support Set. In Cassandra the 
collection types includes "set" which Cassandra Java Driver treat it as 
LinkedHashSet. 

I have a column defined type set<test>. And in the Java Pojo, I set it as 
Set<String>.

It will success in Cassandra binding, but fail in Solr with following error:
Caused by: java.lang.IllegalArgumentException: Can not set java.util.Set field 
com.xxx.xxxx to java.util.ArrayList
        
But If I set it Pojo to List<String>, Solr binding will success, but Cassandra 
will fail and give me error as bellow:
argument type mismatch - had objects of type "java.util.LinkedHashSet" but 
expected signature "java.util.List"

I believe following code may need an update? Which only care about List and Map.

    <T> void inject(T obj, SolrDocument sdoc) {
      Object val = getFieldValue(sdoc);
      if(val == null) {
        return;
      }

      if (isArray && !isContainedInMap) {
        List list;
        if (val.getClass().isArray()) {
          set(obj, val);
          return;
        } else if (val instanceof List) {
          list = (List) val;
        } else {
          list = new ArrayList();
          list.add(val);
        }
        set(obj, list.toArray((Object[]) Array.newInstance(type, list.size())));
      } else if (isList && !isContainedInMap) {
        if (!(val instanceof List)) {
          List list = new ArrayList();
          list.add(val);
          val =  list;
        }
        set(obj, val);
      } else if (isContainedInMap) {
        if (val instanceof Map) {
          set(obj,  val);
        }
      } else {
        set(obj, val);
      }

    }




--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to