Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-10364

Solr bean binding only support List and Map?

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 4.10.4, 6.4.2
    • 4.10.4
    • SolrJ
    • None

    Description

      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); }

      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            guhuaping Huaping Gu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: