Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-2300

Can't read and convert DBRef when the type is Map.

    XMLWordPrintable

    Details

      Description

      If I try to fetch data without using a data model, the List with DBRef is not a problem, but there is a problem with the Map.

       

      mongoTemplate.findOne(query, Object.class, COLLECTION_NAME)
      
      // It works fine
      {  
        "_id": NumberLong(25),  
        "resourceKey": "A",  
        "contents": {    
          "cluster": [      
            {
              "$ref": "clusters",
              "$id": NumberLong(537168)
            }
          ]
        }
      }
      
      // NPE
      {
          "_id" : NumberLong(25),
          "resourceKey" : "A",
          "contents" : {
          "cluster" : {
              "$ref" : "clusters",
              "$id" : NumberLong(329688)
          }
      }

       

      In readCollectionOrArray function has a logic to check null but readMap doesn't.

       

      // readCollectionOrArray
      TypeInformation<?> componentType = targetType.getComponentType() != null //
            ? targetType.getComponentType() //
            : ClassTypeInformation.OBJECT;
      Class<?> rawComponentType = componentType.getType();
      
      
      // readMap
      // rawValueType is null
      map.put(key, DBRef.class.equals(rawValueType) ? value
            : readAndConvertDBRef((DBRef) value, defaultedValueType, ObjectPath.ROOT, rawValueType))

       

      I changed code like this and test in my project, and it works fine.

      https://github.com/topjung3/spring-data-mongodb/commit/615fbeefad7151cd237ec3df18106652da8072e0

       

      Thanks.

        Attachments

          Activity

            People

            Assignee:
            cstrobl Christoph Strobl
            Reporter:
            topjung3 Heesu Jung
            Last updater:
            Mark Paluch
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: