use of org.jnosql.artemis.Converters in project jnosql-artemis by eclipse.
the class ConverterUtil method getValue.
public static Object getValue(Object value, ClassRepresentation representation, String name, Converters converters) {
Optional<FieldRepresentation> fieldOptional = representation.getFieldRepresentation(name);
if (fieldOptional.isPresent()) {
FieldRepresentation field = fieldOptional.get();
Field nativeField = field.getNativeField();
if (!nativeField.getType().equals(value.getClass())) {
return field.getConverter().map(converters::get).map(a -> a.convertToDatabaseColumn(value)).orElseGet(() -> Value.of(value).get(nativeField.getType()));
}
return field.getConverter().map(converters::get).map(a -> a.convertToDatabaseColumn(value)).orElse(value);
}
return value;
}
Aggregations