use of org.springframework.cloud.gcp.data.datastore.core.mapping.DatastoreDataException in project spring-cloud-gcp by spring-cloud.
the class DefaultDatastoreEntityConverter method readAsMap.
@Override
public <T, R> Map<T, R> readAsMap(BaseEntity entity, TypeInformation mapTypeInformation) {
Assert.notNull(mapTypeInformation, "mapTypeInformation can't be null");
if (entity == null) {
return null;
}
Map<T, R> result;
if (!mapTypeInformation.getType().isInterface()) {
try {
result = (Map<T, R>) ((Constructor<?>) mapTypeInformation.getType().getConstructor()).newInstance();
} catch (Exception e) {
throw new DatastoreDataException("Unable to create an instance of a custom map type: " + mapTypeInformation.getType() + " (make sure the class is public and has a public no-args constructor)", e);
}
} else {
result = new HashMap<>();
}
EntityPropertyValueProvider propertyValueProvider = new EntityPropertyValueProvider(entity, this.conversions);
Set<String> fieldNames = entity.getNames();
for (String field : fieldNames) {
result.put(this.conversions.convertOnRead(field, NOT_EMBEDDED, mapTypeInformation.getComponentType()), propertyValueProvider.getPropertyValue(field, EmbeddedType.of(mapTypeInformation.getMapValueType()), mapTypeInformation.getMapValueType()));
}
return result;
}
Aggregations