Skip to content

Commit

Permalink
Merge pull request #1 from AndersonMartinsDev/fix-nofieds
Browse files Browse the repository at this point in the history
FIX- quando a classe B tem o atributo e a A não foi corrigido
  • Loading branch information
AndersonMartinsDev authored Oct 17, 2024
2 parents ff3d72d + 4ee3af1 commit 381a087
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>mart-mapper</groupId>
<artifactId>dto-mapper</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
<name>mapper</name>
<description></description>
<properties>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/convert/impl/ParseToNewClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -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> E setValue(Field field, Object old) {
try {
var value = getValueOld(field, old);
Expand Down Expand Up @@ -57,6 +59,9 @@ private <E> E getNewInstance(Class clazz) {


private <E> 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);
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/mocks/ClassA.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@AllArgsConstructor
@Builder
public class ClassA {

private Long ides;
private String text;
private Integer number;
private LocalDate date;
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/mocks/ClassB.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

@ToString
public class ClassB {

private Integer id;
private String text;
private Integer number;
private LocalDate date;
Expand Down

0 comments on commit 381a087

Please sign in to comment.