Closed alain-marcel closed 4 years ago
@alain-marcel Thank you for noticing and providing the solution. I have integrated this fix in the PR: https://github.com/microsoft/spring-data-cosmosdb/pull/430
This will get released with 2.1.8 sometime next week.
Hi
Used versions : com.microsoft.azure:spring-data-cosmosdb:2.1.7 and 3.0.0.M1)
If we declare an ObjectMapper, then it is not used in following case : File: com.microsoft.azure.spring.data.cosmosdb.core.DocumentDbTemplate Method: find(@NonNull DocumentQuery query, @NonNull Class domainClass, String collectionName)
Line 279 : .map(cosmosItemProperties -> cosmosItemProperties.toObject(domainClass))
In fact, the implementation should use mappingDocumentDbConverter attribute to deserialize object.
Workaround
The key code is to override find method :
Action
Could you please integrate this in next version ? Thanks.
Full MyDocumentDbTemplate.java
package org.me;
import com.azure.data.cosmos.CosmosClient; import com.azure.data.cosmos.CosmosItemProperties; import com.azure.data.cosmos.FeedOptions; import com.azure.data.cosmos.SqlQuerySpec; import com.microsoft.azure.spring.data.cosmosdb.CosmosDbFactory; import com.microsoft.azure.spring.data.cosmosdb.core.DocumentDbTemplate; import com.microsoft.azure.spring.data.cosmosdb.core.convert.MappingDocumentDbConverter; import com.microsoft.azure.spring.data.cosmosdb.core.generator.FindQuerySpecGenerator; import com.microsoft.azure.spring.data.cosmosdb.core.query.DocumentQuery; import com.microsoft.azure.spring.data.cosmosdb.exception.DocumentDBAccessException; import com.microsoft.azure.spring.data.cosmosdb.repository.support.DocumentDbEntityInformation; import org.springframework.lang.NonNull; import org.springframework.util.Assert; import reactor.core.publisher.Flux;
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors;
public class MyDocumentDbTemplate extends DocumentDbTemplate { private final MappingDocumentDbConverter mappingDocumentDbConverter; private final String databaseName; private final CosmosClient cosmosClient;
}