Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiffIgnore does not work for a collection of ValueObject #810

Closed
cervandt opened this issue Mar 20, 2019 · 2 comments
Closed

DiffIgnore does not work for a collection of ValueObject #810

cervandt opened this issue Mar 20, 2019 · 2 comments
Labels
bug Core Team This issue will be implemented by JaVers core team fixed

Comments

@cervandt
Copy link

After recent fix #795 , DiffIgnore on the method stopped working for a set of ValueObjects having a set of ValueObjects. It is expected that for MappingStyle = BEAN, DiffIgnore should be on the method rather than field.

If I set DiffIgnore on getNumber() method, javers is finding differences. But if I add DiffIgnore on the field "number", javers is not finding differences (which is expected).

Expected result: DiffIgnore on the method getNumber() should work and no differences should be found.

It looks like it stopped working since v 5.2.5.

Here is the code:

`import org.javers.core.Javers;
import org.javers.core.JaversBuilder;
import org.javers.core.MappingStyle;
import org.javers.core.diff.Diff;
import org.javers.core.diff.ListCompareAlgorithm;
import org.javers.core.metamodel.annotation.DiffIgnore;
import org.javers.core.metamodel.annotation.Id;
import java.util.*;

public class Test {
private final static Javers differ = JaversBuilder.javers()
.withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE)
.withMappingStyle(MappingStyle.BEAN)
.build();

public static class Building {
    private Integer id;
    private Set<Floor> floors;

    @Id
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Set<Floor> getFloors() {
        return floors;
    }

    public void setFloors(Set<Floor> floors) {
        this.floors = floors;
    }
}

public static class Floor {
    private Set<Room> rooms;

    public Set<Room> getRooms() {
        return rooms;
    }

    public void setRooms(Set<Room> rooms) {
        this.rooms = rooms;
    }
}

public static class Room {
    private String name;
    
    private String number;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @DiffIgnore
    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }
}

public static void main(String[] args) {
    Building building1 = new Building();
    building1.setId(1);
    Room room1 = new Room();
    room1.setName("Room!");
    room1.setNumber("Ignore me");
    Floor floor1 = new Floor();
    floor1.setRooms(Collections.singleton(room1));
    building1.setFloors(Collections.singleton(floor1));

    Building building2 = new Building();
    building2.setId(1);
    Room room2 = new Room();
    room2.setName("Room!");
    room2.setNumber("Different room");
    Floor floor2 = new Floor();
    floor2.setRooms(Collections.singleton(room2));
    building2.setFloors(Collections.singleton(floor2));

    Diff diff = differ.compare(building1, building2);
    System.out.println(diff.getChanges().size());
}

}`

bartoszwalacik added a commit that referenced this issue Mar 20, 2019
@bartoszwalacik
Copy link
Member

You are right, it's a bug, thanks for reporting.

@bartoszwalacik bartoszwalacik added bug Core Team This issue will be implemented by JaVers core team labels Mar 20, 2019
bartoszwalacik added a commit that referenced this issue Mar 20, 2019
@bartoszwalacik
Copy link
Member

fixed in 5.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Core Team This issue will be implemented by JaVers core team fixed
Projects
None yet
Development

No branches or pull requests

2 participants