Skip to content

compare wrongly returns UNTOUCHED #212

New issue

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

By clicking “No 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? No Sign in to your account

Open
Kira-Cesonia opened this issue Jun 26, 2020 · 0 comments
Open

compare wrongly returns UNTOUCHED #212

Kira-Cesonia opened this issue Jun 26, 2020 · 0 comments

Comments

@Kira-Cesonia
Copy link

I have two quite different objects

	public static GameCharacter sylvia() {
		
		String characterName = "Sylvia the Hero";
		
		String weaponName = "Gryphclaw";
		int attack = 255;
		Weapon weapon = new Weapon(weaponName, attack);
		
		String armorName = "Starscale Armor";
		int defense = 231;
		Armor armor = new Armor(armorName, defense);
		
		String _id = "sylv01";
		
		List<Item> inventory = new ArrayList<Item>();
		Potion potion = new Potion("Hi-Potion", 3);
		inventory.add(potion);
		Ether ether = new Ether("Mega Ether", 5, 200);
		inventory.add(ether);
		
		GameCharacter sylvia = new GameCharacter(characterName, weapon, armor, _id, inventory);
		return sylvia;
	}
	
	public static GameCharacter sylviaEdited() {
		
		String characterName = "Sylvia Zerin";
		
		String weaponName = "Luberjack's Axe";
		int attack = 7;
		Weapon weapon = new Weapon(weaponName, attack);
		
		String armorName = "Crude Mazoiscale Armor";
		int defense = 13;
		Armor armor = new Armor(armorName, defense);
		
		String _id = "sylv01";
		
		List<Item> inventory = new ArrayList<Item>();
		Potion potion = new Potion("Hi-Potion", 2);
		inventory.add(potion);
		Tonic tonic = new Tonic("Full Tonic", 2, 100);
		inventory.add(tonic);
		
		GameCharacter sylvia = new GameCharacter(characterName, weapon, armor, _id, inventory);
		return sylvia;
	}

When comparing them like this:

		GameCharacter sylvia = GameCharacters.sylvia();
		GameCharacter sylviaEdited = GameCharacters.sylviaEdited();
		
		DiffNode cityDelta
			= objectDiffer.compare(sylvia, sylviaEdited);

...the resulting DiffNode tells reads / => UNTOUCHED, even though the two compared objects are quite different.

Looking through the issues, I have found mentions of this being because the objects are POJOs and not JavaBeans. I have also seen mention of an Introspector and the IntrospectionConfiguration. I have been trying to figure something out with this, but have not come to a solution.

Is it possible to adequately compare objects like these?

public class GameCharacter {
	@Id
	public String _id;
	public String name;
	public Weapon weapon;
	public Armor armor;
	public List<Item> inventory;
	
	public GameCharacter() {
		
	}
	
	public GameCharacter(String name, Weapon weapon, Armor armor, String _id, List<Item> inventory) {
		this._id = _id;
		this.name = name;
		this.weapon = weapon;
		this.armor = armor;
		this.inventory = inventory;
	}
}

The main question here is if it is possible to somehow use java-object-diff without the need to implement getters and setters.

For reference, you can find all the files and my attempts in the following repository:
https://github.com/Kira-Cesonia/tri-JaDe
Check out the delta.DeltaApplierTest

No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant