private <T> T convertCustomType(Map<String, Object> source, TypeInformation<?> propertyType) { TypeInformation<?> typeToUse = typeMapper.readType(source, propertyType); AerospikePersistentEntity<?> entity = mappingContext.getPersistentEntity(typeToUse); RecordReadingPropertyValueProvider propertyValueProvider = new RecordReadingPropertyValueProvider(source); PersistentPropertyAccessor persistentPropertyAccessor = getConvertingPropertyAccessor(entity, propertyValueProvider); return (T) convertProperties(entity, propertyValueProvider, persistentPropertyAccessor); }
private Map<String, Object> convertProperties(TypeInformation<?> type, AerospikePersistentEntity<?> entity, ConvertingPropertyAccessor accessor) { Map<String, Object> target = new HashMap<>(); typeMapper.writeType(type, target); entity.doWithProperties((PropertyHandler<AerospikePersistentProperty>) property -> { Object value = accessor.getProperty(property); if (isNotWritable(property)) { return; } Object valueToWrite = getValueToWrite(value, property.getTypeInformation()); if(valueToWrite != null) { target.put(property.getFieldName(), valueToWrite); } }); return target; }
@Override @SuppressWarnings("unchecked") public <R> R read(Class<R> targetClass, final AerospikeReadData data) { if (data == null) { return null; } Map<String, Object> record = data.getRecord(); TypeInformation<? extends R> typeToUse = typeMapper.readType(record, ClassTypeInformation.from(targetClass)); Class<? extends R> rawType = typeToUse.getType(); if (conversions.hasCustomReadTarget(AerospikeReadData.class, rawType)) { return conversionService.convert(data, rawType); } AerospikePersistentEntity<?> entity = mappingContext.getPersistentEntity(typeToUse); RecordReadingPropertyValueProvider propertyValueProvider = new RecordReadingPropertyValueProvider(data.getKey(), record); ConvertingPropertyAccessor accessor = getConvertingPropertyAccessor(entity, propertyValueProvider); AerospikePersistentProperty idProperty = entity.getIdProperty(); if (idProperty != null) { Object value = getIdValue(data.getKey(), record, idProperty); accessor.setProperty(idProperty, value); } AerospikePersistentProperty expirationProperty = entity.getExpirationProperty(); if (expirationProperty != null) { Object value = getExpiration(data, expirationProperty); accessor.setProperty(expirationProperty, value); } return convertProperties(entity, propertyValueProvider, accessor); }
TypeInformation<?> readType = typeMapper.readType(source); TypeInformation<?> typeToUse = readType != null ? readType : ClassTypeInformation.from(type); final TarantoolPersistentEntity<?> entity = mappingContext.getPersistentEntity(typeToUse);