From 4ee3af1ffc8aed2945f47b7d31b1b4af825883f4 Mon Sep 17 00:00:00 2001 From: Anderson M Date: Thu, 17 Oct 2024 17:33:57 -0300 Subject: [PATCH] =?UTF-8?q?FIX-=20quando=20a=20classe=20B=20tem=20o=20atri?= =?UTF-8?q?buto=20e=20a=20A=20n=C3=A3o=20foi=20corrigido?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/convert/impl/ParseToNewClass.java | 5 +++++ src/test/java/mocks/ClassA.java | 2 ++ src/test/java/mocks/ClassB.java | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b4598ea..37a582e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ mart-mapper dto-mapper - 0.0.1 + 0.0.2 mapper diff --git a/src/main/java/convert/impl/ParseToNewClass.java b/src/main/java/convert/impl/ParseToNewClass.java index 55fb459..e3b3315 100644 --- a/src/main/java/convert/impl/ParseToNewClass.java +++ b/src/main/java/convert/impl/ParseToNewClass.java @@ -7,6 +7,8 @@ public abstract class ParseToNewClass { + //TODO: Resolver problema na biblioteca do mapper -> quando não possui o atributo na classe que receberá os valors eles dá uma excessão java.lang.NoSuchFieldException + //TODO: Ajustar testes unitários para que contemple cenários como o citado private E setValue(Field field, Object old) { try { var value = getValueOld(field, old); @@ -57,6 +59,9 @@ private E getNewInstance(Class clazz) { private E getValueOld(Field field, Object oldValue) throws NoSuchFieldException, IllegalAccessException { + if(Arrays.stream(oldValue.getClass().getDeclaredFields()).filter(f-> f.getName().equalsIgnoreCase(field.getName())).count() == 0){ + return null; + } var value = oldValue.getClass().getDeclaredField(field.getName()); value.setAccessible(true); return (E) value.get(oldValue); diff --git a/src/test/java/mocks/ClassA.java b/src/test/java/mocks/ClassA.java index f60c45d..da72531 100644 --- a/src/test/java/mocks/ClassA.java +++ b/src/test/java/mocks/ClassA.java @@ -15,6 +15,8 @@ @AllArgsConstructor @Builder public class ClassA { + + private Long ides; private String text; private Integer number; private LocalDate date; diff --git a/src/test/java/mocks/ClassB.java b/src/test/java/mocks/ClassB.java index 7d44a9e..ebd403d 100644 --- a/src/test/java/mocks/ClassB.java +++ b/src/test/java/mocks/ClassB.java @@ -9,6 +9,8 @@ @ToString public class ClassB { + + private Integer id; private String text; private Integer number; private LocalDate date;