Skip to content

Commit

Permalink
refactor: avoid use of Field as native at convert util
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed Jul 30, 2023
1 parent 4a9ee1a commit 7f757cf
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ public static Object getValue(Object value, EntityMetadata mapping, String name,
* @return tje value converted
*/
public static Object getValue(Object value, Converters converters, FieldMetadata field) {
Field nativeField = field.nativeField();
if (!field.type().equals(value.getClass())) {
return field.converter()
.map(converters::get)
.map(useConverter(value))
.orElseGet(getSupplier(value, nativeField));
.orElseGet(getSupplier(value, field.type()));
}

return field.converter()
Expand All @@ -78,16 +77,16 @@ public static Object getValue(Object value, Converters converters, FieldMetadata
.orElse(value);
}

private static Supplier<Object> getSupplier(Object value, Field nativeField) {
private static Supplier<Object> getSupplier(Object value, Class<?> type) {
return () -> {
if (Iterable.class.isAssignableFrom(nativeField.getType())) {
if (Iterable.class.isAssignableFrom(type)) {
return value;
}
try {
return Value.of(value).get(nativeField.getType());
return Value.of(value).get(type);
} catch (UnsupportedOperationException ex) {
LOGGER.fine(String.format("There is an error when try to convert the type %s to the type %s",
value, nativeField.getType()));
value, type));
return value;
}

Expand Down

0 comments on commit 7f757cf

Please sign in to comment.