private Optional<Long> getLastModifiedInMilliseconds(Object object) { return getAuditableBeanWrapper(object)// .flatMap(it -> it.getLastModifiedDate())// .map(it -> conversionService.convert(it, Date.class))// .map(it -> conversionService.convert(it, Instant.class))// .map(it -> it.toEpochMilli()); } }
value, valueType.getSimpleName(), targetValueType.getSimpleName())); return conversionService.convert(value, targetValueType);
@Override public <T> T getProperty(String key, Class<T> targetValueType) { Object value = properties.get(key); if (value == null){ return null; }else{ return conversionService.convert(value, targetValueType); } }
private Optional<Long> getLastModifiedInMilliseconds(Object object) { return getAuditableBeanWrapper(object)// .flatMap(it -> it.getLastModifiedDate())// .map(it -> conversionService.convert(it, Date.class))// .map(it -> conversionService.convert(it, Instant.class))// .map(it -> it.toEpochMilli()); } }
/** * Checks whether we have a custom conversion registered for the given value into an arbitrary simple JDBC type. * Returns the converted value if so. If not, we perform special enum handling or simply return the value as is. * * @param value to be converted. Must not be {@code null}. * @return the converted value if a conversion applies or the original value. Might return {@code null}. */ @Nullable private Object getPotentiallyConvertedSimpleWrite(Object value) { Optional<Class<?>> customTarget = conversions.getCustomWriteTarget(value.getClass()); if (customTarget.isPresent()) { return conversionService.convert(value, customTarget.get()); } return Enum.class.isAssignableFrom(value.getClass()) ? ((Enum<?>) value).name() : value; }
/** * Checks whether we have a custom conversion registered for the given value into an arbitrary simple JDBC type. * Returns the converted value if so. If not, we perform special enum handling or simply return the value as is. * * @param value to be converted. Must not be {@code null}. * @return the converted value if a conversion applies or the original value. Might return {@code null}. */ @Nullable private Object getPotentiallyConvertedSimpleWrite(Object value) { Optional<Class<?>> customTarget = conversions.getCustomWriteTarget(value.getClass()); if (customTarget.isPresent()) { return conversionService.convert(value, customTarget.get()); } return Enum.class.isAssignableFrom(value.getClass()) ? ((Enum<?>) value).name() : value; }
/** * Checks whether we have a custom conversion registered for the given value into an arbitrary simple JDBC type. * Returns the converted value if so. If not, we perform special enum handling or simply return the value as is. * * @param value to be converted. Must not be {@code null}. * @return the converted value if a conversion applies or the original value. Might return {@code null}. */ @Nullable private Object getPotentiallyConvertedSimpleWrite(Object value) { Optional<Class<?>> customTarget = conversions.getCustomWriteTarget(value.getClass()); if (customTarget.isPresent()) { return conversionService.convert(value, customTarget.get()); } return Enum.class.isAssignableFrom(value.getClass()) ? ((Enum<?>) value).name() : value; }
@SuppressWarnings("unchecked") public <T> T convert(Object sourceValue, Class<T> targetType) { Class<?> boxedSourceType = ConversionUtils.boxIfNeeded(sourceValue.getClass()); Class<T> boxedTargetType = ConversionUtils.boxIfNeeded(targetType); return boxedTargetType.isAssignableFrom(boxedSourceType) ? (T) sourceValue : this.conversionService.convert(sourceValue, boxedTargetType); }
@SuppressWarnings("unchecked") public <T> T convert(Object sourceValue, Class<T> targetType) { Class<?> boxedSourceType = ConversionUtils.boxIfNeeded(sourceValue.getClass()); Class<T> boxedTargetType = ConversionUtils.boxIfNeeded(targetType); return boxedTargetType.isAssignableFrom(boxedSourceType) ? (T) sourceValue : this.conversionService.convert(sourceValue, boxedTargetType); }
private String convertValueToDurationIfPossible(final String value) { try { val service = applicationContext.getEnvironment().getConversionService(); val dur = service.convert(value, Duration.class); if (dur != null) { return String.valueOf(dur.toMillis()); } } catch (final ConversionFailedException e) { LOGGER.trace(e.getMessage()); } return null; } }
private Integer getResolvedValueIfPossible(ConfigurableEnvironment environment, String value) { String resolvedValue = environment.resolveRequiredPlaceholders(value); return environment.getConversionService().convert(resolvedValue, Integer.class); }
@SuppressWarnings("unchecked") <T> T convert(Object value, Class<T> targetType) { return (T) configurableConversionService.convert(value, TypeDescriptor.forObject(value), TypeDescriptor.valueOf(targetType)); }
@Override @Nullable public Object readValue(@Nullable Object value, TypeInformation<?> type) { if (null == value) { return null; } if (conversions.hasCustomReadTarget(value.getClass(), type.getType())) { return conversionService.convert(value, type.getType()); } return getPotentiallyConvertedSimpleRead(value, type.getType()); }
@Override @Nullable public Object readValue(@Nullable Object value, TypeInformation<?> type) { if (null == value) { return null; } if (conversions.hasCustomReadTarget(value.getClass(), type.getType())) { return conversionService.convert(value, type.getType()); } return getPotentiallyConvertedSimpleRead(value, type.getType()); }
@Override @Nullable public Object readValue(@Nullable Object value, TypeInformation<?> type) { if (null == value) { return null; } if (conversions.hasCustomReadTarget(value.getClass(), type.getType())) { return conversionService.convert(value, type.getType()); } return getPotentiallyConvertedSimpleRead(value, type.getType()); }
@Override public <T> T getGlobalConfigurationValue(final String configurationKeyName, final Class<T> propertyType) { final TenantConfigurationKey key = tenantConfigurationProperties.fromKeyName(configurationKeyName); if (!key.getDataType().isAssignableFrom(propertyType)) { throw new TenantConfigurationValidatorException(String.format( "Cannot parse the database value of type %s into the type %s.", key.getDataType(), propertyType)); } return conversionService.convert(key.getDefaultValue(), propertyType); }
@Override public <T> T getGlobalConfigurationValue(final String configurationKeyName, final Class<T> propertyType) { final TenantConfigurationKey key = tenantConfigurationProperties.fromKeyName(configurationKeyName); if (!key.getDataType().isAssignableFrom(propertyType)) { throw new TenantConfigurationValidatorException(String.format( "Cannot parse the database value of type %s into the type %s.", key.getDataType(), propertyType)); } return conversionService.convert(key.getDefaultValue(), propertyType); }
@Override @Nullable public Object writeValue(@Nullable Object value, TypeInformation<?> type) { if (value == null) { return null; } Class<?> rawType = type.getType(); RelationalPersistentEntity<?> persistentEntity = context.getPersistentEntity(value.getClass()); if (persistentEntity != null) { Object id = persistentEntity.getIdentifierAccessor(value).getIdentifier(); return writeValue(id, type); } if (rawType.isInstance(value)) { return getPotentiallyConvertedSimpleWrite(value); } return conversionService.convert(value, rawType); }
@Override @Nullable public Object writeValue(@Nullable Object value, TypeInformation<?> type) { if (value == null) { return null; } Class<?> rawType = type.getType(); RelationalPersistentEntity<?> persistentEntity = context.getPersistentEntity(value.getClass()); if (persistentEntity != null) { Object id = persistentEntity.getIdentifierAccessor(value).getIdentifier(); return writeValue(id, type); } if (rawType.isInstance(value)) { return getPotentiallyConvertedSimpleWrite(value); } return conversionService.convert(value, rawType); }
@Override public <T extends Serializable> TenantConfigurationValue<T> buildTenantConfigurationValueByKey( final TenantConfigurationKey configurationKey, final Class<T> propertyType, final TenantConfiguration tenantConfiguration) { if (tenantConfiguration != null) { return TenantConfigurationValue.<T> builder().global(false).createdBy(tenantConfiguration.getCreatedBy()) .createdAt(tenantConfiguration.getCreatedAt()) .lastModifiedAt(tenantConfiguration.getLastModifiedAt()) .lastModifiedBy(tenantConfiguration.getLastModifiedBy()) .value(conversionService.convert(tenantConfiguration.getValue(), propertyType)).build(); } else if (configurationKey.getDefaultValue() != null) { return TenantConfigurationValue.<T> builder().global(true).createdBy(null).createdAt(null) .lastModifiedAt(null).lastModifiedBy(null) .value(getGlobalConfigurationValue(configurationKey.getKeyName(), propertyType)).build(); } return null; }